php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #45912 wanted: eval() that works in a separate variable space
Submitted: 2008-08-25 18:45 UTC Modified: 2013-02-17 12:51 UTC
From: ganswijk at xs4all dot nl Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 5.3CVS-2008-08-25 (CVS) OS: irrelevant
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2008-08-25 18:45 UTC] 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



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-26 18:43 UTC] 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'.
 [2013-02-17 12:51 UTC] nikic@php.net
Agree that just running it in a function should be enough.
 [2013-02-17 12:51 UTC] nikic@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: *General Issues
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 17:01:33 2024 UTC