note 45703 deleted from function.func-get-args by bjori
| From: | bjori@php.net | Date: | Tue, 25 Apr 2006 19:11:01 +0000 |
| Subject: | note 45703 deleted from function.func-get-args by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-109674@lists.php.net to get a copy of this message | ||
Note Submitter: tightcode_nosp@m_hotmail
----
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