Bug #72254 [Opn]: get_object_vars() returns unusable result when keys are numeric

From: Date: Thu, 02 Jun 2016 12:32:07 +0000
Subject: Bug #72254 [Opn]: get_object_vars() returns unusable result when keys are numeric
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-201405@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72254&edit=1 ID: 72254 Updated by: cmb@php.net Reported by: unirgy at gmail dot com Summary: get_object_vars() returns unusable result when keys are numeric Status: Open Type: Bug Package: Scripting Engine problem Operating System: Any PHP Version: 7.0.6 Block user comment: N Private report: N New Comment: > Our manual is not correct about object to array cast. It does > not have to be inaccessible like above. When casting from array to object, and casting back to array, numeric keys are indeed accessible. However, constructing an object with numeric keys, and casting to array, makes numeric keys inaccessible, see <https://3v4l.org/Gsjtv>. While this is somewhat inconsistent for itself, json's behavior is consistent with this inconsistent behavior. Previous Comments: ------------------------------------------------------------------------ [2016-05-25 00:12:01] yohgaki@php.net I'm not sure why JSON does special(?) thing. In general, array with numeric index should be able to be accessed. https://3v4l.org/VIhtW Our manual is not correct about object to array cast. It does not have to be inaccessible like above. We should avoid inconsistent behavior. It seems some overhead is required fix this inconsistency. Question would be "is it too severe or not?". ------------------------------------------------------------------------ [2016-05-24 10:37:57] cmb@php.net Isn't this basically the same issue as bug #70925? ------------------------------------------------------------------------ [2016-05-23 01:37:52] yohgaki@php.net IMO. 5.6's behavior is right one. If $var is array and has 1 as key, it must be accessible as $var[1] and/or $var['1'] ------------------------------------------------------------------------ [2016-05-23 01:08:03] unirgy at gmail dot com Just to confirm, are you saying this is an expected behavior and change from 5.6? ------------------------------------------------------------------------ [2016-05-23 00:59:20] yohgaki@php.net https://3v4l.org/7tshA PHP 7 behaves like HHVM. PHP 5.6 does not. ------------------------------------------------------------------------ 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=72254 -- Edit this bug report at https://bugs.php.net/bug.php?id=72254&edit=1

« previous php.bugs (#201405) next »