note 84140 added to function.eval
| From: | marco at harddisk dot is-a-geek dot org | Date: | Mon, 30 Jun 2008 17:44:53 +0000 |
| Subject: | note 84140 added to function.eval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-141015@lists.php.net to get a copy of this message | ||
eval does not work reliably in conjunction with global, at least not in the cygwin port version.
So:
<?PHP
class foo {
//my class...
}
function load_module($module) {
eval("global \$".$module."_var;");
eval("\$".$module."_var=&new foo();");
//various stuff ... ...
}
load_module("foo");
?>
becomes to working:
<?PHP
class foo {
//my class...
}
function load_module($module) {
eval('$GLOBALS["'.$module.'_var"]=&new foo();');
//various stuff ... ...
}
load_module("foo");
?>
Note in the 2nd example, you _always_ need to use $GLOBALS[$module] to access the variable!
----
Server IP: 212.124.37.9
Probable Submitter: 62.216.215.89
----
Manual Page -- http://www.php.net/manual/en/function.eval.php
Edit -- https://master.php.net/note/edit/84140
Del: integrated -- https://master.php.net/note/delete/84140/integrated
Del: useless -- https://master.php.net/note/delete/84140/useless
Del: bad code -- https://master.php.net/note/delete/84140/bad+code
Del: spam -- https://master.php.net/note/delete/84140/spam
Del: non-english -- https://master.php.net/note/delete/84140/non-english
Del: in docs -- https://master.php.net/note/delete/84140/in+docs
Del: other reasons-- https://master.php.net/note/delete/84140
Reject -- https://master.php.net/note/reject/84140
Search -- https://master.php.net/manage/user-notes.php