note 106481 modified in function.eval by danbrown
| From: | danbrown@php.net | Date: | Tue, 15 Nov 2011 16:29:53 +0000 |
| Subject: | note 106481 modified in function.eval by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-184480@lists.php.net to get a copy of this message | ||
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"
?>
--was--
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:
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"
http://php.net/manual/en/function.eval.php