Bug #80380 [Com]: Cannot access numeric property in ArrayObject

From: Date: Wed, 27 Jan 2021 11:19:51 +0000
Subject: Bug #80380 [Com]: Cannot access numeric property in ArrayObject
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-231792@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80380&edit=1 ID: 80380 Comment by: debrawade19 at gmail dot com Reported by: anton at rudnikov dot net Summary: Cannot access numeric property in ArrayObject Status: Verified Type: Bug Package: SPL related Operating System: any PHP Version: 7.4.12 Block user comment: N Private report: N New Comment: Much obliged for sharing a particularly incredible data. https://igarageband.org/ Previous Comments: ------------------------------------------------------------------------ [2020-11-23 18:26:52] cmb@php.net Yes, that is another instance of the same root cause, which is that ArrayObject treats object properties ("proptables") as arrays ("symtables"). Yet another instance: <?php $object = new stdClass; $object->{'1'} = 'test1'; $arrayObject = new ArrayObject($object); $arrayObject['2'] = 'test2'; var_dump($object); ?> We have just created an inaccessible numeric property on the stdClass instance. It seems to me that the fix is not trivial, and that it might break some existing code. As such, I don't think this should be fixed for any stable PHP version, but rather documented. ------------------------------------------------------------------------ [2020-11-20 08:17:34] anton at rudnikov dot net There's also interesting behaviour when I try to get array copy from ArrayObject using method getArrayCopy. Test script: --------------- <?php $object = new stdClass(); $object->prop = 'test1'; $object->{'1'} = 'test2'; $arrayObject = new ArrayObject($object); $arrayCopy = $arrayObject->getArrayCopy(); var_dump($arrayCopy[1], $arrayCopy['1']); // can't access numeric property on array copy $array = (array) $object; var_dump($array[1], $array['1']); // but it works if I just cast stdClass to array var_dump($arrayCopy, $array); // let's see differences between arrays Actual result: -------------- Notice: Undefined offset: 1 in /tmp/preview on line 8 Notice: Undefined offset: 1 in /tmp/preview on line 8 NULL NULL string(4) "test" string(4) "test" array(1) { ["1"]=> string(4) "test" } array(1) { [1]=> string(4) "test" } ------------------------------------------------------------------------ [2020-11-19 12:32:08] cmb@php.net The following pull request has been associated: Patch Name: Fix #80380: Cannot access numeric property in ArrayObject On GitHub: https://github.com/php/php-src/pull/6436 Patch: https://github.com/php/php-src/pull/6436.patch ------------------------------------------------------------------------ [2020-11-19 11:34:02] cmb@php.net Given that numeric properties are accessible after array conversion as of PHP 7.2.0, it seems wrong that this is not the case with ArrayObjects. ------------------------------------------------------------------------ [2020-11-19 09:42:17] anton at rudnikov dot net Changed package ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=80380 -- Edit this bug report at https://bugs.php.net/bug.php?id=80380&edit=1

« previous php.bugs (#231792) next »