|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-07-22 01:00 UTC] david at grudl dot com
Description:
------------
Invalid UTF-8 string throws E_WARNING depending on the configuration directive display_errors:
ini_set('display_errors', 0);
json_encode("\xFF"); // PHP Warning: json_encode(): Invalid UTF-8 sequence in argument (in error log)
ini_set('display_errors', 1);
json_encode("\xFF"); // *nothing*
This directive determines whether errors should be printed to the screen as part of the output or if they should be hidden from the user. It should not be used to change json_encode behaviour.
The same bug affects htmlentities() and htmlspecialchars()
Test script:
---------------
ini_set('display_errors', 0);
json_encode("\xFF");
htmlspecialchars("\xFF", ENT_COMPAT, 'utf-8');
htmlentities("\xFF", ENT_COMPAT, 'utf-8');
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 14:00:01 2025 UTC |
This is a valid bug. The point of this bug is that no warning ever is issued if display_errors is off. The warnings should still be issued, they just shouldn't be.... displayed. ini_set('display_errors', 1); json_encode("\xFF"); print_r(error_get_last()); //nothing! wtf? ini_set('display_errors', 0); json_encode("\xFF"); print_r(error_get_last()); //now its there!