note 106481 deleted from function.eval by googleguy
| From: | googleguy@php.net | Date: | Fri, 24 Feb 2017 21:11:58 +0000 |
| Subject: | note 106481 deleted from function.eval by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208826@lists.php.net to get a copy of this message | ||
Note Submitter: socram8888 at gmail dot com
----
It may be a bit obvious, but if you don't want eval'd code to interfere with main code
variables, all you have to do is to call an eval from another function like this:
<?php
function localeval($code) {
return eval($code);
};
$a = "a";
echo '$a before eval code: ' . $a . "\n"; // prints "a"
localeval('$a = \'b\';');
echo '$a after localeval: ' . $a . "\n"; // still prints "a"
eval('$a = \'b\';');
echo '$a after eval: ' . $a . "\n"; // prints "b"
?>