note 77112 deleted from language.oop5 by colder

From: Date: Sun, 19 Aug 2007 23:38:33 +0000
Subject: note 77112 deleted from language.oop5 by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-129605@lists.php.net to get a copy of this message
Note Submitter: deimors_at_hotmail_dot_com ---- 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?

« previous php.notes (#129605) next »