Bug #52717 [NEW]: Numeric property name can be set/get via variable but not static
| From: | epicfailmail at tempinbox dot com | Date: | Fri, 27 Aug 2010 09:55:08 +0000 |
| Subject: | Bug #52717 [NEW]: Numeric property name can be set/get via variable but not static | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-153847@lists.php.net to get a copy of this message | ||
From:
Operating system: Windows 7
PHP version: 5.3.3
Package: Class/Object related
Bug Type: Bug
Bug description:Numeric property name can be set/get via variable but not static
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 bug report at http://bugs.php.net/bug.php?id=52717&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=52717&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=52717&r=trysnapshot53
Try a snapshot (trunk): http://bugs.php.net/fix.php?id=52717&r=trysnapshottrunk
Fixed in SVN: http://bugs.php.net/fix.php?id=52717&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52717&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=52717&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=52717&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=52717&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=52717&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=52717&r=support
Expected behavior: http://bugs.php.net/fix.php?id=52717&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=52717&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=52717&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=52717&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52717&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=52717&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=52717&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=52717&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=52717&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=52717&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=52717&r=mysqlcfg