|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-12-06 03:06 UTC] deligo2003 at yahoo dot ca
[2008-12-31 16:32 UTC] felipe@php.net
[2009-01-22 01:07 UTC] jani@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 09:00:02 2025 UTC |
Description: ------------ var_export(), get_object_vars(), and ReflectionObject do not recognize or handle object properties correctly that are coerced from a numerically indexed array or an array with string keys of any integer except for zero. ie: (object)array(1,2,3,4); ie: (object)array('1' => 1, '-5' => 2, '3' => 3, '-10' => 4); Values seem to have no effect. There may be other functions/classes that do not handle these types of property names correctly. The samples included only show the results of ReflectionObject::getProperties(), but also functions like ReflectionObject::hasProperty() incorrectly returns false, for example. Reproduce code: --------------- <?php $a = (object)array(1, 2, 3, 4); echo '<pre>'; var_dump($a); print_r($a); var_export($a); print_r(get_object_vars($a)); $r = new ReflectionObject($a); print_r($r->getProperties()); ?> Expected result: ---------------- var_export($a); output: stdClass::__set_state(array(1,2,3,4)) print_r(get_object_vars($a)); output: Array([0]=>1,[1]=>2,[2]=>3,[3]=>4) print_r($r->getProperties()); output: Array( [0]=>ReflectionProperty Object ( [name]=>0 [class]=>stdClass ) ... and so on up to [3] ) Actual result: -------------- var_export($a); output: stdClass::__set_state(array()) print_r(get_object_vars($a)); output: Array() print_r($r->getProperties()); output: note: this result varies ie1: Array ( [0] => ReflectionProperty Object ( [name] => ?.C?6??Xl??Ћ??*?v\?#?I?I [class] => stdClass ) [1] => ReflectionProperty Object ( [name] => M??F?Xl??Ћ?? [class] => stdClass ) ) ie2: Array ( [0] => ReflectionProperty Object ( [name] => F7??5?h?? ??oMWM=[?*?"?I [class] => stdClass ) )