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/20/06 18:12

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

>> 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'.
>
> Ah. Why not use str_replace?

The replacing part is not a problem.

> And when you are using classes, you could as easily define a Variable
> class with a Name and a Value method, and even a ToTemplate method
> that puts the two pairs of curly braces around them.

I'm not sure I follow you here. I'm trying to get value names *from* a
string, and then get the values for those names.

> If this is for a template engine, you probably have the name/value
> pairs in a "named" array.

For some values, yes. But in other cases, such as error reporting, I need
to access an actual variable.

Anyway, I have it worked out now. But thank you for answering.

--
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

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