|
Posted by Tommy Gildseth on 02/24/06 22:27
m.epper@gmail.com wrote:
>
> The problem is that this code will be run from eval which is inside
> another function.
> In this case the php engine will parse something like this:
>
> <?php
> function myFunction($code){
> $var="Hello";
> function myFunction2(){
> global $var;
> $var.=" World";
> }
>
> myFunction2();
> echo $var;
> }
> myFunction($code);
> ?>
>
> Here the output will be only "Hello" because myFunction2 (which should
> add " World" to $var) will try to change the value of $var, a global
> variable that doesn't exists!.
Your problem here, is that the variable $var isn't in the global scope to
begin with, it's in the scope of the function myFunction, and even though
myFunction2() is created within myFunction(), it does not inherit
myFunction()'s scope or variables.
The only solution that I can think of right now, would be if you both in
myFunction() and in the eval'ed code containing myFunction2() refer to the
variables via the $GLOBALS array instead of directly using the variable
name.
--
Tommy
http://design.twobarks.com/
[Back to original message]
|