note 77112 added to language.oop5
| From: | deimors_at_hotmail_dot_com at osu1 dot php dot net | Date: | Wed, 15 Aug 2007 21:09:51 +0000 |
| Subject: | note 77112 added to language.oop5 | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129506@lists.php.net to get a copy of this message | ||
I've run into a bit of a problem I'm hoping someone can help me with. I'm trying to
create an array as a member of an object, containing another member of that object. I'm trying
something like:
<?
class A {
public $a = "foo";
public $b = array($this->a);
}
?>
which gives me:
PHP Parse error: syntax error, unexpected T_VARIABLE, expecting ')' in foo.php on line 4
However, the following works perfectly fine:
<?
$a = "foo";
$b = array($a);
?>
Now, it seems that if I initialize $b in the constructor, all's fine, such as:
<?
class A {
public $a = "foo";
public $b;
function __construct() {
$this->b = array($this->a);
}
}
?>
Is there a way to pull off what I'm trying to do (apart from using the constructor), or is this
simply a limitation of the parser I've gotta live with?
----
Server IP: 66.207.199.35
Probable Submitter: 70.65.24.9
----
Manual Page -- http://www.php.net/manual/en/language.oop5.php
Edit -- https://master.php.net/note/edit/77112
Del: integrated -- https://master.php.net/note/delete/77112/integrated
Del: useless -- https://master.php.net/note/delete/77112/useless
Del: bad code -- https://master.php.net/note/delete/77112/bad+code
Del: spam -- https://master.php.net/note/delete/77112/spam
Del: non-english -- https://master.php.net/note/delete/77112/non-english
Del: in docs -- https://master.php.net/note/delete/77112/in+docs
Del: other reasons-- https://master.php.net/note/delete/77112
Reject -- https://master.php.net/note/reject/77112
Search -- https://master.php.net/manage/user-notes.php