Re: pass by reference variable length args

From: Date: Wed, 06 Jan 2010 04:01:53 +0000
Subject: Re: pass by reference variable length args
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-300843@lists.php.net to get a copy of this message
viraj wrote:
hi all, i'm trying to write a wrapper function for "mysqli_stmt_bind_results". and expect it to work the same way it accepts and bind results to the original function. the problem is, i couldn't find a way to pass the args by reference via func_get_args and register the out put from call_user_func_array to the caller scope.. any idea? here goes few lines which i'm trying hard for past 48 hours.. with no luck.. :( class stmt {
       private $stmt;
       public function bind_result() {
$argsToBindResult = func_get_args(); $argList = array($this->stmt); $argList = array_merge($argList, $argsToBindResult); call_user_func_array('mysqli_stmt_bind_result', $argList); } } $stmt->prepare('SELECT name,email FROM users WHERE id = ?'); $stmt->bind_param('i',2); .. .. $stmt->bind_result($name,$email); echo $name,$email;
You're out of luck for using the func_get_args() call. The following method (albeit a dirty method) works: <?php function bind_stuff( &$arg1, &$arg2=null, &$arg3=null, &$arg4=null, &$arg5=null, &$arg6=null, &$arg7=null, &$arg8=null, &$arg9=null ) {
    for( $i = 1; $i <= 9; $i++ )
    {
        ${'arg'.$i} = 'bound'.$i;
    }
} bind_stuff( $name, $email ); echo $name."\n"; echo $email."\n"; ?> Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP

« previous php.general (#300843) next »