Reply to Re: Execute code in global scope

Your name:

Reply:


Posted by m.epper on 02/24/06 22:09

Anonoymous:
1) Read here, my problem is a bit more complicated.
2) I've read the manual

Jerry Stuckle:
Thanks for the tips.

I know about global and I also know that in the example I've written, a
parameter (is better to say argument?) function would have been better.

My problem is a bit more complicated:

The main script is like this:

<?php
function myFunction($code){
eval($code);
}
myFunction($code);
?>

$code is a var which contains php istructions (without <?php and ?>)
from another file.
This code is written to work indipendently and should be something like
this one:

$var="Hello";
function myFunction2(){
global $var;
$var.=" World";
}

myFunction2();
echo $var;

In this case, if the code works alone, the output will be "Hello
World".

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

I've some restrictions: I can't change $code and I can't put eval
outside functions or directly into the main script.
So my question is: "Is there any way to evaluate some php code from a
function, but into the global scope?"

Thank you
(I suppose to have made some errors now, is this true? :D )

[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

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