#44347 [Opn->Bgs]: $foo[x] = y; syntax doesn't work inside a class
| From: | felipe@php.net | Date: | Thu, 06 Mar 2008 00:52:25 +0000 |
| Subject: | #44347 [Opn->Bgs]: $foo[x] = y; syntax doesn't work inside a class | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-122989@lists.php.net to get a copy of this message | ||
ID: 44347
Updated by: felipe@php.net
Reported By: rewilliams at newtekit dot com
-Status: Open
+Status: Bogus
Bug Type: Class/Object related
Operating System: OS X 10.2.5
PHP Version: 5.2.5
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
See http://docs.php.net/manual/en/language.oop5.basic.php
Previous Comments:
------------------------------------------------------------------------
[2008-03-05 23:35:21] rewilliams at newtekit dot com
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 this bug report at http://bugs.php.net/?id=44347&edit=1