|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-02-17 07:16 UTC] wynn dot chen dot cn at gmail dot com
[2016-07-25 16:56 UTC] cmb@php.net
-Status: Open
+Status: Not a bug
-Assigned To:
+Assigned To: cmb
[2016-07-25 16:56 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 19:00:01 2025 UTC |
Description: ------------ Take the test script below and save it as UTF-8 and verify: > cat test.php | tail -n 4 | head -n 1 | hexdump -C 00000000 09 23 20 c3 a4 c3 b6 0a |.# .....| 00000008 Now run > ./bin/php test.php | hexdump -C PHP Version = 5.4.8 zend.multibyte = 1 00000000 58 00 00 00 |X...| 00000004 As you can see PHP added three NUL bytes to the file. Now remove one of the characters in the commented out line: > ./bin/php test.php | hexdump -C PHP Version = 5.4.8 zend.multibyte = 1 00000000 58 00 00 |X..| 00000003 As you can see the NUL bytes are directly related to the amount of non-ASCII characters in the file. Now comment out the declare statement: > ./bin/php test.php | hexdump -C PHP Version = 5.4.8 zend.multibyte = 1 00000000 58 |X| 00000001 This time the output is correct. Tested with off-the-shelf PHP, but also happens with ubuntu packaged 5.4.6-1 Also happends when PHP is running as Apache module where this issue caused corrupted images for me. Test script: --------------- <?php declare(encoding='UTF-8'); fwrite(STDERR,"PHP Version = ".phpversion()."\n"); fwrite(STDERR,"zend.multibyte = ".ini_get('zend.multibyte')."\n"); # äöü echo "X"; ?> Expected result: ---------------- See above. UTF-8 declared files with UTF-8 content should work fine. Actual result: -------------- See above. UTF-8 declared files with UTF-8 content produce NUL bytes in the output.