ID:               45912
 Comment by:       ganswijk at xs4all dot nl
 Reported By:      ganswijk at xs4all dot nl
 Status:           Open
 Bug Type:         Feature/Change Request
 Operating System: irrelevant
 PHP Version:      5.3CVS-2008-08-25 (CVS)
 New Comment:

I have experimented some more and I may have spoken too hastily because
most of what I wanted can be achieved by putting the eval() inside of a
function like this:

function restricted_eval($php_code) {
  global $allowed_global_variable;

  return eval($php_code);
}

This way the eval() environment consists of only the environment
within the restricted_eval() function which in this example only
has access to the variable $allowed_global_variable'.


Previous Comments:
------------------------------------------------------------------------

[2008-08-25 18:45:47] ganswijk at xs4all dot nl

Description:
------------
I'd like a version of eval() that works in a separate environment
(variable namespace) so it can't clutter up the main script. Probably
it's best to give the name of an environment for example an object/array
name as a second argument to eval(), so the programmer can decide if two
successive calls of eval should work on the same or separate
environments. There is probably no problem with the main program having
access to the namespaces of the eval() calls.

For example (assuming that the separate environment is just an
object/array in the main program):

$a=1;

eval('$a=2;',$environment1);

echo $a;  //shows 1

echo $environment1.a;  //shows 2

eval('echo $a;',$environment1);  //shows 2
eval('echo $a;',$environment2);  //shows nothing or undefined




------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=45912&edit=1

Reply via email to