Hola.
Is it just me, or is eval() just a giant pain in the tookus?...
Here's my issue. I'd really like to know if anyone knows something on this subject that I don't.
I'm using an XSLT/XML setup to produce PHP pages that are cached for later use. When I load the pages from cache (i.e. they are loaded direct to the browser via include()), everything is fine.
The admin for this system allows the administrator to preview any changes he's made before the result string is saved to the cache file. I do this by taking the result string (i.e. the string containing the new PHP page) and eval()'ing it. That looks like:
eval("?>" . $result);
The result string contains an include() statement that pulls in a piece of 3rd party code that uses a bunch of functions (to sum up: within the eval, a bunch of functions are declared.) These functions use global to pull in some variables that are also declared inside the eval() within it's top-level scope. I ran some tests, and these globaled vars don't make it into the function scope. Here's an example of what I mean:
FILE myfile.php:
<?php
$globalvar = "stuff";
function my_func() {
global $globalvar;
if (isset($globalvar)) {
echo "it's real";
} else {
echo "it's not real";
}
}
?>
FILE main.php:
<?php
$str = join("",file("myfile.php"));
eval("?>" . $str);
?>
According to my experience, the output of running main.php would be
it's not real
This would be imply that global cannot be used inside an eval()? Any experience to the contrary or to the agreement?
Thanks much, all!
-Roy