Reputation: 1
<?php
$str1 = "";
$str2 = "\0";
var_dump(ord($str1), ord($str2));
var_dump(strlen($str1), strlen($str2), $str1 === $str2);
debug_zval_dump($str1, $str2);
?>
Result:
Upvotes: 0
Views: 9754
Reputation: 869
Looks correct, ord() is expecting a character to be passed, and because you pass an empty string, it just assumes a NULL character (\0). Php strings are not null terminated, you can have perfectly legal strings with null characters within them.
To PHP a '\0' is just a string with one character in it.
Edit:
A PHP string is stored as list of all the characters in the string, and the total length. This allows PHP to store any character value, from 0 to 255. C Strings use the NULL character to determine where the string ends, PHP only uses the length to determine how long the string is.
Upvotes: 1
Reputation: 575
Since PHP is built on C and null-bytes (\0) denote the end of a string in C, I would say it's something to do with that. PHP.net has an article on null bytes and the issues they can cause:
http://php.net/manual/en/security.filesystem.nullbytes.php
Upvotes: 0