Re: pass by reference variable length args

From: Date: Wed, 06 Jan 2010 05:30:41 +0000
Subject: Re: pass by reference variable length args
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-300846@lists.php.net to get a copy of this message
viraj wrote:
if func_get_args supports pass by reference, we could have avoid the loop and pre-defined arg list. something like.. extract(func_get_args) :D
Absolute! I'm not sure why there isn't some kind of way to retrieve a reference in this manner, but I suspect it's related to knowing which parameters were set as reference appropriate values. For instance contrast the following:
    bind_stuff( $id, $test );
Versus the following:
    bind_stuff( 5, $test );
Defining the function parameters to use references will generate a fatal error when 5 is passed since this is a fatal error. How then to enable variable args to achieve the same result? I guess one could ask PHP to support something like the following:
    $args = func_bind_args( array( true, true ) );
Where $args would then contain a reference where the corresponding index was set to true in the argument list. Since this isn't very variable, then the last index set would denote the default for all other args. Thus the example above could be shortened:
    $args = func_bind_args( array( true ) );
Or even:
    $args = func_bind_args( true );
Since this is run-time too, then PHP could generate an E_WARNING instead of E_FATAL and bind a copy instead when no reference was passed. On further thought, the current func_get_args() could be adapted in this manner since it currently accepts no arguments. Anyways... just thoughts. I hit this problem in the past too :) Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP

« previous php.general (#300846) next »