Carl Furst wrote:
You mean like this ?
<?
$file string = file_get_contents(urlencode($file_path));
<http://us3.php.net/manual/en/function.file-get-contents.php>
$result = eval($file_string);
?>
Well I see a few problems with this. One is that scope is not lexical.
In other words if $foo exists somewhere in the script and $foo also
exists in $file_string then $foo will retain the value it was set to in
$file_string. That could lead to some debugging hell. Also, you would
have to collect the output and manually return it which means you would
have to keep an output cache which means you could only use scripts that
cached output and returned them explicitly. However, the flip side is
you could have a buffer declared in the local scope that collects the
output of $file_string and then put that in the message, but that is not
the same as:
$foo = include $bar; # this is, of course, impossible
If you want the include to have it's own variable scope then wrap it
with a function. If you want to assign the resulting value via a single
call then wrap it in a function. Fortunately both of these combined
require one thing... wrap it in a function.
<?php
function eval_include( $path )
{
ob_start();
include( $path );
$result = ob_get_contents();
ob_end_clean();
return $result;
}
$foo = eval_include( $bar );
?>
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php