note 74994 added to function.func-get-args
| From: | ario | Date: | Mon, 07 May 2007 21:50:58 +0000 |
| Subject: | note 74994 added to function.func-get-args | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-126306@lists.php.net to get a copy of this message | ||
"Because this function depends on the current scope to determine parameter details, it cannot
be used as a function parameter. If you must pass this value, assign the results to a variable, and
pass the variable."
This means that the following code generates an error:
<?php
function foo($list)
{
echo implode(', ', $list);
}
function foo2()
{
foo(func_get_args());
}
foo2(1, 2, 3);
?>
However, you can easily get around this by doing the following:
<?php
function foo($list)
{
echo implode(', ', $list);
}
function foo2()
{
foo($args = func_get_args());
}
foo2(1, 2, 3);
?>
This captures the context from foo2(), making this legal. You get the expected output:
"1, 2, 3"
----
Server IP: 69.39.81.135
Probable Submitter: 66.90.152.115
----
Manual Page -- http://www.php.net/manual/en/function.func-get-args.php
Edit -- https://master.php.net/note/edit/74994
Del: integrated -- https://master.php.net/note/delete/74994/integrated
Del: useless -- https://master.php.net/note/delete/74994/useless
Del: bad code -- https://master.php.net/note/delete/74994/bad+code
Del: spam -- https://master.php.net/note/delete/74994/spam
Del: non-english -- https://master.php.net/note/delete/74994/non-english
Del: in docs -- https://master.php.net/note/delete/74994/in+docs
Del: other reasons-- https://master.php.net/note/delete/74994
Reject -- https://master.php.net/note/reject/74994
Search -- https://master.php.net/manage/user-notes.php