Req #45912 [Opn->Wfx]: wanted: eval() that works in a separate variable space
| From: | nikic@php.net | Date: | Sun, 17 Feb 2013 12:51:42 +0000 |
| Subject: | Req #45912 [Opn->Wfx]: wanted: eval() that works in a separate variable space | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-176683@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=45912&edit=1
ID: 45912
Updated by: nikic@php.net
Reported by: ganswijk at xs4all dot nl
Summary: wanted: eval() that works in a separate variable
space
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: *General Issues
Operating System: irrelevant
PHP Version: 5.3CVS-2008-08-25 (CVS)
Block user comment: N
Private report: N
New Comment:
Agree that just running it in a function should be enough.
Previous Comments:
------------------------------------------------------------------------
[2008-08-26 18:43:27] ganswijk at xs4all dot nl
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'.
------------------------------------------------------------------------
[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 https://bugs.php.net/bug.php?id=45912&edit=1