Edit report at http://bugs.php.net/bug.php?id=52717&edit=1
ID: 52717 Comment by: + at ni-po dot com Reported by: epicfailmail at tempinbox dot com Summary: Numeric property name can be set/get via variable but not static Status: Open Type: Bug Package: Class/Object related Operating System: Windows 7 PHP Version: 5.3.3 Block user comment: N New Comment: Use the complex variable syntax: $obj->{0} or $obj->{"0"} will work. Previous Comments: ------------------------------------------------------------------------ [2010-08-27 11:55:07] epicfailmail at tempinbox dot com Description: ------------ It is not possible to assign a numeric (integer or string) property name directly but via a variable. Test script: --------------- <?php $obj = new stdClass; $zero_int = 0; $zero_str = "0"; $obj->$zero_int = "bar"; // works $obj->$zero_str = "bar"; // works $obj->0 = "bar"; // Parse error: syntax error, unexpected T_LNUMBER, expecting T_STRING or T_VARIABLE or '{' or '$' in foo.php on line 9 $obj->"0" = "bar"; // Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_STRING or T_VARIABLE or '{' or '$' in foo.php on line 10 print_r($obj->$zero_int); // works print_r($obj->$zero_str); // works print_r($obj->0); // Parse error: syntax error, unexpected T_LNUMBER, expecting T_STRING or T_VARIABLE or '{' or '$' in foo.php on line 13 print_r($obj->"0"); // Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_STRING or T_VARIABLE or '{' or '$' in foo.php on line 15 ?> Expected result: ---------------- I expected that both ways or neither of them would work. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=52717&edit=1