Edit report at https://bugs.php.net/bug.php?id=63745&edit=1
ID: 63745 Updated by: ahar...@php.net Reported by: jesper dot hag at gmail dot com Summary: Var_dump on null characters -Status: Open +Status: Not a bug Type: Feature/Change Request -Package: *General Issues +Package: Variables related Operating System: CentOS PHP Version: 5.3Git-2012-12-11 (Git) Block user comment: N Private report: N New Comment: var_dump() dumps the contents of the string as is, so the null byte is literally a null byte in the output. If you run your test script through hexdump, you get this: adamh@swiftdesk7:~$ php /tmp/test.php | hexdump -C 00000000 73 74 72 69 6e 67 28 36 29 20 22 00 32 33 34 35 |string(6) ".2345| 00000010 36 22 0a |6".| 00000013 You can see the null byte in the output. What you probably want instead of var_export(), which will escape non-printable characters: for instance, your test string is exported as: '' . "\0" . '23456' Previous Comments: ------------------------------------------------------------------------ [2012-12-11 19:04:19] jesper dot hag at gmail dot com Description: ------------ *Note* My PHP version is actually 5.3.3 The problem I've come up to is that printing a string with var_dump (for debugging purpose eg.) that contains null-characters are counted in the string length but are not in any way displayed in the var_dump output. I'm not sure this should be considerate a bug or a feature request because it is something I want and perhaps not something that per design should be in this way. Test script: --------------- <?php $string = "123456"; // len 6 $string[0] = ''; (or = null, or = "\0") var_dump($string); // Outputs string(6) "23456" ?> Expected result: ---------------- I would expect the above script to output something like string(6) "\0123456", that - in my world - would make more sense. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=63745&edit=1