note 24285 added to function.eval
| From: | Ben dot Dischinger at ndsu dot nodak dot edu | Date: | Mon, 12 Aug 2002 06:44:02 +0000 |
| Subject: | note 24285 added to function.eval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-34838@lists.php.net to get a copy of this message | ||
I came across this little gem of a function while I was trying to instantiate general objects from
an array of parameters. The return from within the eval function solves many problems.
function newByList($Class,$Params) {
$Params = stripslashes($Params);
return eval("return new $Class($Params);");
}
class A {
function A ($a,$b,$c) {
echo "$a $b $c";
}
}
newByList("A","1,2,3");
Output: 1 2 3
This could be useful for saving/restoring objects by mirroring instead of serialization.
--
http://www.php.net/manual/en/function.eval.php
http://master.php.net/manage/user-notes.php?action=edit+24285
http://master.php.net/manage/user-notes.php?action=delete+24285
http://master.php.net/manage/user-notes.php?action=reject+24285