From: juzna dot cz at gmail dot com
Operating system: Ubuntu 10.04
PHP version: 5.4.6
Package: JSON related
Bug Type: Bug
Bug description:errors json_encode do NOT call error handler
Description:
------------
When there is an error within json_encode (e.g. due to invalid utf8),
E_WARNING
should be raised. However, that doesn't happen in some cases.
It doesn't happen when display_errors is set to On.
In latest snapshot of 5.4 it does not happen at all.
Test script:
---------------
<?php
/**
* WTF? Error handler is not called, when display_errors=On
*
* _errorHandler must be called in each case, but it's not.
*
* Results differ on different PHP versions.
*/
function _errorHandler($severity, $message, $file, $line, $context) {
$GLOBALS['err'] = func_get_args();
// echo "Error ($severity) $message in $file:$line\n";
}
set_error_handler('_errorHandler');
// display_errors = Off, works fine
{
ini_set('display_errors', 0);
// Calls error handler, fine
$err = NULL;
$tmp = substr(new stdClass(), 1, 1);
var_dump($err[0], $err[1]);
// Calls error handler, fine
$err = NULL;
$tmp = json_encode(array("bad utf\xFF"));
var_dump($err[0], $err[1]);
}
// display_errors = On, WTF???
{
ini_set('display_errors', 1);
// Calls error handler, fine
$err = NULL;
$tmp = substr(new stdClass(), 1, 1);
var_dump($err[0], $err[1]);
// Does NOT call error handler, WTF???
$err = NULL;
$tmp = json_encode(array("bad utf\xFF"));
var_dump($err[0], $err[1]);
}
Expected result:
----------------
int(2)
string(55) "substr() expects parameter 1 to be string, object given"
int(2)
string(49) "json_encode(): Invalid UTF-8 sequence in argument"
int(2)
string(55) "substr() expects parameter 1 to be string, object given"
int(2)
string(49) "json_encode(): Invalid UTF-8 sequence in argument"
Actual result:
--------------
On 5.4.6:
int(2)
string(55) "substr() expects parameter 1 to be string, object given"
int(2)
string(49) "json_encode(): Invalid UTF-8 sequence in argument"
int(2)
string(55) "substr() expects parameter 1 to be string, object given"
NULL
NULL
On 5.4-latest:
int(2)
string(55) "substr() expects parameter 1 to be string, object given"
NULL
NULL
int(2)
string(55) "substr() expects parameter 1 to be string, object given"
NULL
NULL
--
Edit bug report at https://bugs.php.net/bug.php?id=63004&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=63004&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=63004&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=63004&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=63004&r=fixed
Fixed in SVN and need be documented:
https://bugs.php.net/fix.php?id=63004&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=63004&r=alreadyfixed
Need backtrace:
https://bugs.php.net/fix.php?id=63004&r=needtrace
Need Reproduce Script:
https://bugs.php.net/fix.php?id=63004&r=needscript
Try newer version:
https://bugs.php.net/fix.php?id=63004&r=oldversion
Not developer issue:
https://bugs.php.net/fix.php?id=63004&r=support
Expected behavior:
https://bugs.php.net/fix.php?id=63004&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=63004&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=63004&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=63004&r=globals
PHP 4 support discontinued:
https://bugs.php.net/fix.php?id=63004&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=63004&r=dst
IIS Stability:
https://bugs.php.net/fix.php?id=63004&r=isapi
Install GNU Sed:
https://bugs.php.net/fix.php?id=63004&r=gnused
Floating point limitations:
https://bugs.php.net/fix.php?id=63004&r=float
No Zend Extensions:
https://bugs.php.net/fix.php?id=63004&r=nozend
MySQL Configuration Error:
https://bugs.php.net/fix.php?id=63004&r=mysqlcfg