You are here: Re: [PHP] Passing variable number of parameters by reference « PHP « IT news, forums, messages
Re: [PHP] Passing variable number of parameters by reference

Posted by Marek Kilimajer on 05/13/05 05:24

I believe it's mentioned somewhere in the manual you can't do that.
func_get_arg() always return a copy. You can workaround this using an array.

Robert Meyer wrote:
> Hello,
>
> Using: PHP Version 5.0.3
>
> I build the following function:
>
> function Set4HTMLOut() {
> $C = func_num_args();
> for ($I = 0; $I < $C; $I++) {
> $A = func_get_arg($I);
> echo 'I['.$I.']('.strlen($A).'): '.$A.'<br />';
> $A = htmlspecialchars($A);
> echo 'I['.$I.']('.strlen($A).'): '.$A.'<br />';
> }
> }
>
> And called it like this:
>
> Set4HTMLOut(&$LName, &$LOrg, &$LWebSite, &$LPhones, &$LComments);
> echo '<br />After call:<br />'.
> 'LName: '.$LName.'<br />'.
> 'LOrg: '.$LOrg.'<br />'.
> 'LWebSite: '.$LWebSite.'<br />'.
> 'LPhones: '.$LPhones.'<br />'.
> 'LComments: '.$LComments.'<br />';
>
> The "echo" statements in the Set4HTMLOut() function echos all the correct
> data and proves the data was received correctly then altered by the
> htmlspecialchars() function appropriately. Notice that the caller passes
> each variable as a reference. Yet, the "echo" statement after the call
> displays the data without any changes, like the first "echo" statement in
> the Set$HTMLOut() function does.
>
> Is it not possible to pass variables by reference to a variable-length
> parameter list? Or am I doing something wrong? If so, what?
>
> I have already built a work around. I do not need any work arounds. I just
> think one should be able to pass variables by reference to a function that
> accepts a variable-length parameter list.
>
> Regards
>
> Robert
>

 

Navigation:

[Reply to this 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

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