|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-08-14 00:43 UTC] php at hristov dot com
[2005-04-28 19:41 UTC] dmitry@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 20:00:01 2025 UTC |
Description: ------------ If I try to use variable with non-string name (e.g. $x = 10; $$x = ...) the name is converted to a string using standard conversion rules. That's ok. But this doesn't work on object's field which is IMHO a bug and it implies some a buggy behavior. See the code bellow. It seems that by: $x = null; $a->$x = "whatever"; one can somehow create a private variable (or something like that, don't know what ":private" means)! Moreover, there is possibly a bug in get_object_vars when a field name is a numeric string (e.g. "10") (compare the first item of results of get_object_vars and var_dump). Reproduce code: --------------- function field_names_test() { $a = new stdClass(); $x = 10; $a->$x = "int(10)"; $x = "10"; $a->$x = "string('10')"; $x = ""; $a->$x = "string('')"; $x = null; $a->$x = "null"; $x = 1.8; $a->$x = "double(1.8)"; $x = false; $a->$x = "bool(false)"; $x = array(1,2,3); $a->$x = "array(1,2,3)"; var_dump(get_object_vars($a)); var_dump($a); } field_names_test(); Expected result: ---------------- array(4) { ["10"]=> string(12) "string('10')" [""]=> string(11) "bool(false)" ["1.8"]=> string(11) "double(1.8)" ["Array"]=> string(12) "array(1,2,3)" } object(stdClass)#1 (4) { ["10"]=> string(12) "string('10')" [""]=> string(11) "bool(false)" ["1.8"]=> string(11) "double(1.8)" ["Array"]=> string(12) "array(1,2,3)" } Actual result: -------------- array(3) { [10]=> string(12) "string('10')" ["1.8"]=> string(11) "double(1.8)" ["Array"]=> string(12) "array(1,2,3)" } object(stdClass)#1 (4) { ["10"]=> string(12) "string('10')" [":private"]=> string(11) "bool(false)" ["1.8"]=> string(11) "double(1.8)" ["Array"]=> string(12) "array(1,2,3)" }