From: rewilliams at newtekit dot com Operating system: OS X 10.2.5 PHP version: 5.2.5 PHP Bug Type: Class/Object related Bug description: $foo[x] = y; syntax doesn't work inside a class
Description: ------------ If you try to use this syntax in a class to declare a class member: $foo[1] = 1; You get a parse error. Prepending a visibility keyword doesn't change anything, nor does using a string key instead of a numeric key. Note: this was seen in v5.2.4. I don't have 5.2.5 to test against. I did, however, test it against a couple of 5.0.x versions, where I also saw a parse error, so this is definitely a multi-version issue. Reproduce code: --------------- File test.php <?php class foo { $bar[1] = 1; } ?> Expected result: ---------------- I'd expect $bar[1] to be created as member of class foo and assigned the value of 1. This syntax isn't explicitly covered in the classes section of the docs as far as I can see; the only restriction that's given is this: "The default value must be a constant expression, not (for example) a variable, a class member or a function call." Since I'm assigning a constant value, since this array assignment syntax is otherwise valid, and since the array() syntax works, I'd expect this syntax to work, as well. Actual result: -------------- % php -l test.php Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in test.php on line 4 Errors parsing test.php -- Edit bug report at http://bugs.php.net/?id=44347&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=44347&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=44347&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=44347&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=44347&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=44347&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=44347&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=44347&r=needscript Try newer version: http://bugs.php.net/fix.php?id=44347&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=44347&r=support Expected behavior: http://bugs.php.net/fix.php?id=44347&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=44347&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=44347&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=44347&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=44347&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=44347&r=dst IIS Stability: http://bugs.php.net/fix.php?id=44347&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=44347&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=44347&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=44347&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=44347&r=mysqlcfg