note 83566 added to function.func-get-args
| From: | kentfredric at gmail dot com | Date: | Sun, 01 Jun 2008 17:55:25 +0000 |
| Subject: | note 83566 added to function.func-get-args | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-140055@lists.php.net to get a copy of this message | ||
Re This Note:
Note: Because this function depends on the current scope to determine parameter details, it cannot
be used as a function parameter. If this value must be passed, the results should be assigned to a
variable, and that variable should be passed.
And In reply to ario [a] mail [dot] utexas [dot] edu
It would appear the code posted by ario is now in fact valid. ( 5.2.6-pl1-gentoo )
And in fact, the following code works perfectly.
<?php
function foo( $a, $b=null , $c=null )
{
var_export(array($a,$b,$c));
}
function bar()
{
foo( func_get_args() );
}
bar( 4,1,2 );
?>
and so does
<?php
foo( func_get_args() , 1, 2, 3);
?>
It seems the magic is bound to position 1 to let it through.
<?php
function get($a){ return $a; }
function foo(){
var_dump('bar', func_get_args()); // not works
var_dump('bar', get( func_get_args()) ); // not this either
var_dump(func_get_args(),'bar' ); // this works
var_dump(get(func_get_args()),'bar'); // as does this.
}?>
Cool trick that results.
<?php
function cufa( $args, $func ){ return call_user_func_array( $func, $args ); }
function bar( $a, $b, $c,$d )
{
var_dump( $a, $b, $c, $d );
}
function foo(){ return cufa(func_get_args(), 'bar' ); }
function baz(){ return cufa(array_merge(func_get_args(),array('baz')), 'bar' );
}
?>
foo( 1,2,3 );
int(1)
int(2)
int(3)
NULL
baz( 3,2,1 );
int(3)
int(2)
int(1)
string(3) "baz"
----
Server IP: 202.89.58.1
Probable Submitter: 60.234.242.154
----
Manual Page -- http://www.php.net/manual/en/function.func-get-args.php
Edit -- https://master.php.net/note/edit/83566
Del: integrated -- https://master.php.net/note/delete/83566/integrated
Del: useless -- https://master.php.net/note/delete/83566/useless
Del: bad code -- https://master.php.net/note/delete/83566/bad+code
Del: spam -- https://master.php.net/note/delete/83566/spam
Del: non-english -- https://master.php.net/note/delete/83566/non-english
Del: in docs -- https://master.php.net/note/delete/83566/in+docs
Del: other reasons-- https://master.php.net/note/delete/83566
Reject -- https://master.php.net/note/reject/83566
Search -- https://master.php.net/manage/user-notes.php