Reply to Re: Grabbing Arbitrary Amount of Function Arguments by Reference

Your name:

Reply:


Posted by Schraalhans Keukenmeester on 04/02/07 14:41

Curtis wrote:
> Hello everyone:
>
> Recently, I've come across the need to accept an arbitrary amount of
> arguments in my function, but I also need to alter the data in the
> calling scope.
>
> I have been trying to toy around with the func_get_args function,
> however, it seems the data is copied before I can access it, as I tried
> to globalize the values in the argument array and use references, but
> neither worked.
>
> I would be grateful if anyone could point me in the right direction or
> provide any illumination on this subject.
>
> Curtis
Not so elegant as the solution Janwillem provided, but a useable
workaround I once used:
<?PHP
function foo (&$v1,&$v2,&$v3,&$v4,&$v5,&$v6,&$v7,&$v8,&$v9,&$v10) {
$count = func_num_args();
for ($i=1;$i<=$count;$i++){
if (gettype(${"v$i"})=='integer') {
${"v$i"}+=1;
}
}
return true;
}

$a=1;
$b=3;
$c=5;
$d=8;
$e='bar';
@foo ($a,$b,$c,$d,$e); // suppress warnings about missing parameters
echo "$a $b $c $d $e";
// outputs 2 4 6 9 bar
?>

I haven't been able -like you- to alter parameter values when using the
non_parameterized (is that English?) version of a function and
func_get_args(). Perhaps with some devious trickery it is possible to
find the referenced variables somewhere, somehow, but my guess is that
would not be a pure PHP solution.

Of ocurse the function is useless, but with some smart
type-checking-and-branching real nifty stuff could be constructed. I
haven't tested what the practial parameter list length limit is.

HTH

Sh

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация