Bug #70733 [Opn]: int/string conversion bug in arrays

From: Date: Sun, 18 Oct 2015 11:35:19 +0000
Subject: Bug #70733 [Opn]: int/string conversion bug in arrays
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-196675@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70733&edit=1

 ID:                 70733
 Updated by:         laruence@php.net
 Reported by:        bfanger at gmail dot com
 Summary:            int/string conversion bug in arrays
 Status:             Open
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   El Capitan
 PHP Version:        irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

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

:<


Previous Comments:
------------------------------------------------------------------------
[2015-10-18 09:29:39] bfanger at gmail dot com

@laruence But the code snippet doesn't use integers anywhere, but php7 somehow decides to use
the integer 200 instead of the given '200'.

PHP 5.3, 5.3, 5.4, 5.5, 5.6 doesn't have this issue.

------------------------------------------------------------------------
[2015-10-18 07:19:48] laruence@php.net

actually, this is not something new...

because, there are string "200" and interge 200 in the same array.

which is an knew issue.

------------------------------------------------------------------------
[2015-10-17 16:27:45] ab@php.net

Reproduced even with 5.5.

Thanks.

------------------------------------------------------------------------
[2015-10-17 15:43:16] 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
}


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=70733&edit=1


Thread (7 messages)

« previous php.bugs (#196675) next »