note 45703 added to function.func-get-args
| From: | tightcode_nosp at m_hotmail | Date: | Wed, 15 Sep 2004 16:45:32 +0000 |
| Subject: | note 45703 added to function.func-get-args | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-76764@lists.php.net to get a copy of this message | ||
It is possible to use func_get_args() as a parameter!
In addressing "nutbar at innocent dot com" post on the 2003-03-12 @ 09:27, it is worth
noting that there is a work-around.
For people receiving this error:
Fatal error: func_get_args(): Can't be used as a function parameter
The solution is to make sure that func_get_args() is the first function parameter. If it is the
second, third, fourth, etc... it will give that error. However if it is the first or the only
parameter, it is handled as you would expect.
example:
<?php
// Function containing a working example
function working_example($arg1,$arg2) {
return reformat_func_get_args(func_get_args(),"Working Function");
}
// Function containing a non working example
function failing_example($arg1,$arg2) {
return reformat_func_get_args("Failing Function",func_get_args());
}
// Function used to test the working/failing order
function reformat_func_get_args($arg1,$arg2) {
if (is_array($arg1)) {
return $arg2.":".join(",",$arg1);
}
elseif (is_array($arg2)) {
return $arg1.":".join(",",$arg2);
}
else {
return false;
}
}
// This outputs a working example
echo working_example("apples","oranges");
// This throws the above mentioned error
echo failing_example("apples","oranges");
?>
I hope this helps someone. It took me a bit to figure out a way of making it work.
Cheers,
TightCode
----
Manual Page -- http://www.php.net/manual/en/function.func-get-args.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45703
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45703&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45703&report=yes
Search -- http://master.php.net/manage/user-notes.php