note 24285 deleted from function.eval by victor
| From: | victor@php.net | Date: | Sat, 12 Jun 2004 22:39:36 +0000 |
| Subject: | note 24285 deleted from function.eval by victor | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-70999@lists.php.net to get a copy of this message | ||
Note Submitter: Ben.Dischinger@ndsu.nodak.edu
----
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.