You are here: Re: Variable Variables in Classes « PHP Programming Language « IT news, forums, messages
Re: Variable Variables in Classes

Posted by Alan Little on 05/18/06 14:20

Carved in mystic runes upon the very living rock, the last words of
Kimmo Laine of comp.lang.php make plain:

> "Alan Little" <alan@n-o-s-p-a-m-phorm.com> wrote in message
> news:Xns97C6A5C373D05alanphormcom@216.196.97.131...
>> Carved in mystic runes upon the very living rock, the last words of
>> Rik of comp.lang.php make plain:
>>
>>> Alan Little wrote:
>>>> Carved in mystic runes upon the very living rock, the last words of
>>>> Ambush Commander of comp.lang.php make plain:
>>>>
>>>>> It looks like in this particular case, $this->$x should be
>>>>> sufficient.
>>>>
>>>> Thanks, but no.
>>>>
>>>>> Otherwise, you may have to split up x into $x_object and $x_name
>>>>> (exploding by -> should be sufficient) and calling
>>>>> $x_object->$x_name. What you currently have, however, cannot be
>>>>> done.
>>>>
>>>> I'm not sure what you mean.
>>>> What I'm trying to do is parse variables
>>>> out of a string and substitute them with the value. $x (in this
>>>> example) would hold the variable name extracted from the string.
>>>> I'm trying to figure out how to get to the value of that variable,
>>>> from there.
>>>
>>> That is exactly what it does.
>>> $x = 'string'
>>>
>>> $$x = $this->$x;
>>> equals:
>>> $string = $this->string;
>>>
>>> $x is the variable name, $variable_name holds the value......
>>>
>>> I don't get the problem?
>>>
>>> What is the exact reason you're trying to accomplish? Maybe if you
>>> elaborate some more, we get the picture. Why is it this doesn't
>>> suffice?
>>
>> For example:
>>
>> $this->animal = 'lamb';
>> $this->string = 'Mary had a little {{animal}}';
>>
>> The goal is to extract 'animal' from the string (no problem), convert
>> it to 'lamb' and replace it in the string (again, no problem). The
>> question is, if I have 'animal', how do I get 'lamb'? In global
>> space, I would simply have 'animal' in a variable, and use $$var to
>> get 'lamb'.
>
> So again, wouldn't this work:
>
> $var = 'animal';
> $this->$var; //this is translated to $this->animal, which in turn
> gives you 'lamb' .

Yes, that works; I just didn't understand what AB was saying.

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация