Re: Passing an undetermined amount of arguments by reference

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

 



On Wed, 2009-02-04 at 14:02 -0600, Jay Moore wrote:
> Greetings list.
> 
> Say I have a function that escapes a string before being passed to MySQL 
> like so:
> 
> function escape($id, &$string)
> {
> 	$string = mysql_real_escape_string($string, $id);
> }
> 
> I'm passing $string as a reference so I don't have to reassign it like so:
> 
> $foo = escape($id, $foo);
> 
> Simply calling
> 
> escape($id, $foo);
> 
> works just fine.
> 
> 
> How can I do this if I have a variable number of arguments?  I know I 
> can use func_get_args(), func_num_args() and so forth to get the 
> arguments but can I still pass by reference?
> 
> It'd be so much easier to do
> 
> escape($id, $a, $b, $c, $d);
> 
> Than
> 
> $a = escape($id, a);
> 
> and so forth.
> 
> Does this make sense?  Is it possible to do?
> 
> Thanks in advance,
> Jay
> 
What about something like (untested):

list($id, $a, $b, $c, $d) = escape($id, $a, $b, $c, $d);

And then instead of altering the actual values in your function by using
pass-by-reference, you can just return an array of elements instead.


Ash
www.ashleysheridan.co.uk


-- 
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