Bug #52717 [Opn->Nab]: Numeric property name can be set/get via variable but not static

From: Date: Wed, 10 Jun 2015 13:45:31 +0000
Subject: Bug #52717 [Opn->Nab]: Numeric property name can be set/get via variable but not static
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-193310@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=52717&edit=1 ID: 52717 Updated by: cmb@php.net Reported by: epicfailmail at tempinbox dot com Summary: Numeric property name can be set/get via variable but not static -Status: Open +Status: Not a bug Type: Bug Package: Class/Object related Operating System: Windows 7 PHP Version: 5.3.3 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: > Use the complex variable syntax: $obj->{0} or $obj->{"0"} will > work. Exactly. Previous Comments: ------------------------------------------------------------------------ [2010-10-03 18:40:14] + at ni-po dot com Use the complex variable syntax: $obj->{0} or $obj->{"0"} will work. ------------------------------------------------------------------------ [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 https://bugs.php.net/bug.php?id=52717&edit=1

« previous php.bugs (#193310) next »