On Wed, 07 Jul 2004 13:44:21 -0400, Andrew Nagy <[EMAIL PROTECTED]> wrote:
> Curt Zirzow wrote:
> 
> > * Thus wrote Andrew Nagy:
> >
> >>How do you use the call_user_func function with call-time
> >>pass-by-reference deprecation?
> >>
> >>For example:
> >>
> >>function fun(&$arg) {
> >>  $arg++;
> >>}
> >>$var = 0;
> >>call_user_func("fun", $var);
> >>echo $var; //echoes 0 instead of 1
> >
> >
> > $func_call = 'fun';
> > $func_call($var);
> >
> > Curt
> 
> This does not do what I need.  I need to be able to call a dynamic
> function name and pass in the parameters with the &.  The problem is
> this syntax is now deprecated.
> 
> your example with the &:
> 
> $func_call = 'fun';
> $func_call(&$var);
> 
> throughs a warning of the deprecation of this syntax.
> 
> Any ideas?
> 

If you use the $func_name() syntaxt and the function's parameter is
defined as pass-by-reference, this should work fine.

function func(&$a) {
  $a = 1;
}

$a = 0;

$funcName = 'func';
echo '$a before: '.$a.'<br/>';
$funcName($a);
echo '$a after: '.$a.'<br/>';

This doesn't solve the problem if the "dynamic" function also has a
"dynamic" number of parameters, but this should solve at least one
simple problem.

-- 
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder

paperCrane --Justin Patrin--

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

Reply via email to