|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52397 json_encode display_errors dependency
Submitted: 2010-07-22 01:00 UTC Modified: 2010-08-17 14:29 UTC
From: david at grudl dot com Assigned:
Status: Not a bug Package: JSON related
PHP Version: 5.3.3RC3 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: david at grudl dot com
New email:
PHP Version: OS:


 [2010-07-22 01:00 UTC] david at grudl dot com
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);


htmlspecialchars("\xFF", ENT_COMPAT, 'utf-8');

htmlentities("\xFF", ENT_COMPAT, 'utf-8');


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-17 14:29 UTC]
-Status: Open +Status: Bogus
 [2010-08-17 14:29 UTC]
The return values are the same and so is the operation...
 [2011-01-12 01:18 UTC] fake at example dot com
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);
print_r(error_get_last()); //nothing! wtf?

ini_set('display_errors', 0);
print_r(error_get_last()); //now its there!
 [2012-09-03 22:18 UTC] juzna dot cz at gmail dot com
This bug has been upgraded in latest snapshot of 5.4 - json_encode doesn't report 
errors at all :/
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jun 18 12:01:29 2024 UTC