Reply to Re: eval problem

Your name:

Reply:


Posted by Oli Filth on 09/24/06 13:46

iulian.ilea said the following on 24/09/2006 12:54:
> Janwillem Borleffs wrote:
>> iulian.ilea wrote:

>>> function ee($s)
>>> {
>>> return $s;
>>> }
>>>
>>> $v="e(\"name\")";
>>>
>>> eval("$stri=$v;");
>>> echo $stri;

>>> By using eval I want to eval $v and get the result returned by ee
>>> stored in $stri. How woul you do?
>>>
>> Why use eval at all?
>>
>> function ee($s) { return $s; }
>> $str = ee("Bob");
>> print $str;
>
> Thanks, but what I wrote above is just an example. I take the variable
> that must be eval'd from an sql table.

This leads to a further question: Why does your database contain PHP
code? This goes against normal practices of both database and PHP
design. You may be aware of the popular quotation:

"If eval() is the answer, you're almost certainly asking the wrong
question."

i.e. there's probably a better, safer, more programmatic way of doing
what you're doing.


However, the answer to your original problem is that if you want the
string literal '$stri', you must escape the $ character, i.e.:

eval("\$stri = $v;");

Otherwise the value of $stri is substituted into the expression to be
evaluated (and presumably at this point $stri doesn't exist).


--
Oli

[Back to original 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

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