note 74045 added to function.func-get-args
| From: | jmcguire81 | Date: | Wed, 21 Mar 2007 22:13:16 +0000 |
| Subject: | note 74045 added to function.func-get-args | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124690@lists.php.net to get a copy of this message | ||
Here is another variation on accepting a variable number of arguments. This allows for a variable
number of arguments to be passed to a Class constructor, as well as a customized class version to be
used dynamically. Syntax in code is:
$mail = Generator("MailClassName", $db_ref);
function Generator() {
$numargs = func_num_args();
$classname = func_get_arg(0);
$argstring='';
if ($numargs > 1) {
$arg_list = func_get_args();
for ($x=1; $x<$numargs; $x++) {
$argstring .= '$arg_list['.$x.']';
if ($x != $numargs-1) $argstring .= ',';
}
}
if (class_exists("Custom{$classname}")) {
$classname = "Custom{$classname}";
if ($argstring) return eval("return new $classname($argstring);");
return new $classname;
}
if ($argstring) return eval("return new $classname($argstring);");
return new $classname;
}
Hope this is of use to someone.
----
Server IP: 216.194.113.175
Probable Submitter: 69.88.107.94
----
Manual Page -- http://www.php.net/manual/en/function.func-get-args.php
Edit -- https://master.php.net/note/edit/74045
Del: integrated -- https://master.php.net/note/delete/74045/integrated
Del: useless -- https://master.php.net/note/delete/74045/useless
Del: bad code -- https://master.php.net/note/delete/74045/bad+code
Del: spam -- https://master.php.net/note/delete/74045/spam
Del: non-english -- https://master.php.net/note/delete/74045/non-english
Del: in docs -- https://master.php.net/note/delete/74045/in+docs
Del: other reasons-- https://master.php.net/note/delete/74045
Reject -- https://master.php.net/note/reject/74045
Search -- https://master.php.net/manage/user-notes.php