|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-03-06 00:52 UTC] felipe@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 18:00:02 2025 UTC |
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