Re: pass by reference variable length args

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

cheers!

~viraj

On Wed, Jan 6, 2010 at 11:04 AM, viraj <kalinga@xxxxxxxxx> wrote:
> thanks rob!
>
> here goes the working method.
>
> public function bind_result(&$arg1=null,&$arg2=null,&$arg3=null) {
>                $numArgs = func_num_args();
>                $args = array();
>                for ($i=1; $i<= $numArgs; $i++) {
>                         $args['arg' . $i] = &${'arg'.$i};
>                }
>
>                call_user_func_array('mysqli_stmt_bind_result',array_merge(array($this->stmt),$args));
> }
>
>        $stmt->bind_result($id, $test);
>        $stmt->fetch();
>        echo $id, $test;
>
> ~viraj
>
>
> On Wed, Jan 6, 2010 at 10:01 AM, Robert Cummings <robert@xxxxxxxxxxxxx> wrote:
>> 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
>>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux