Re: Re: Classes in PHP5 || Puzzling Problem || Trying to Set $this->$name = $value
| From: | Stut | Date: | Thu, 08 Mar 2007 23:33:15 +0000 |
| Subject: | Re: Re: Classes in PHP5 || Puzzling Problem || Trying to Set $this->$name = $value | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-250135@lists.php.net to get a copy of this message | ||
PHP wrote:
Problem: Class test {Works fine here: http://dev.stut.net/php/classvar.php What do you get? -Stutvar $foo = 0;function __construct() { $this->myfunc("foo", 1); }function myfunc($name, $val) { $this->$name = $val; }} Now, PHP correctly evaluates $this->$name as 0; i.e. the default property value of $this->foo. However, what I really need to have happen is for $this->$name = $val to be evaluated as $this->foo = 1;