|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-10-17 15:43 UTC] bfanger at gmail dot com
Description:
------------
Reading and writing to an array could lead to new array entries (with an integer key) instead of overwriting the value.
This even leads weird json output using which uses same key twice, but that's an other issue.
Test script:
---------------
$object = json_decode('{"200": true}');
$data = get_object_vars($object);
$data['200'] = false;
echo json_encode($data, JSON_PRETTY_PRINT);
Expected result:
----------------
{
"200": false
}
Actual result:
--------------
{
"200": true,
"200": false
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 07 18:00:01 2025 UTC |
that is get_object_vars now reuse the same array of the properties table of stdclass.. like: <?php $object = json_decode('{"200": true}'); $data = (array)($object); var_dump($data); $data['200'] = false; var_dump($data); echo json_encode($data, JSON_PRETTY_PRINT); this will result the same result both on php-5.6 and php7 :<