Re: Re: Classes in PHP5 || Puzzling Problem || Trying to Set $this->$name = $value
| From: | PHP | Date: | Fri, 09 Mar 2007 17:16:36 +0000 |
| Subject: | Re: Re: Classes in PHP5 || Puzzling Problem || Trying to Set $this->$name = $value | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-250165@lists.php.net to get a copy of this message | ||
Hey Stu.
Well, isn't that special ;--)
Jesus, I kept echoing $this->$foo within the parent class and getting 0,
instead of 1.
You wrote your reply; I checked the results again, and, voila, it worked --
obviously I must have been missing something and corrected the mistake in my
endless trial and error process, lol.
In any case, thanks for sorting me out!
-Noah
"Stut" <stuttle@gmail.com> wrote in message
news:45F09D3B.3080301@gmail.com...
> PHP wrote:
>> Problem:
>>
>> Class test {
>>
>> var $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;
>
> Works fine here: http://dev.stut.net/php/classvar.php
>
> What do you get?
>
> -Stut