note 115733 deleted from function.json-encode by crell
| From: | crell@php.net | Date: | Fri, 01 Jul 2022 19:24:53 +0000 |
| Subject: | note 115733 deleted from function.json-encode by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218834@lists.php.net to get a copy of this message | ||
Note Submitter: ninjSPAM at informanceSPAM dot info
----
Although this is not documented on the version log here, non-UTF8 handling behaviour has changed in
5.5, in a way that can make debugging difficult.
Passing a non UTF-8 string to json_encode() will make the function return false in PHP 5.5, while it
will only nullify this string (and only this one) in previous versions.
In a Latin-1 encoded file, write this:
<?php
$a = array('é', 1);
var_dump(json_encode($a));
?>
PHP < 5.4:
string(8) "[null,1]"
PHP >= 5.5:
bool(false)
PHP 5.5 has it right of course (if encoding fails, return false) but its likely to introduce errors
when updating to 5.5 because previously you could get the rest of the JSON even when one string was
not in UTF8 (if this string wasn't used, you'd never notify it's nulled)