|
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
Navigation:
[Reply to this message]
|