Re: [PHP] Variable number of arguments problem

2012-02-12 Thread Stuart Dallas
On 12 Feb 2012, at 18:51, Tim Streater wrote:

 I have a function defined thus:
 
 function my_func ($arg1, $arg2, $arg3, $arg4, $arg5, $arg6)
 {
 
 // code here
 
 }
 
 I call this with variously the first three arguments only, or all six, taking 
 care that if I call it with fewer arguments then I don't try to acces $arg4, 
 $arg5, or $arg6 (which is passed by reference, as is $arg1).
 
 On my first attempt to execute this, I'm getting:
 
  Missing argument 4 for my_func(), called in /path/to/source/file1.php at 
 line 556 and defined
  in /path/to/source/file2.php at line 3
 
 Is this because $arg6 is passed by reference? There is some reference to this 
 in the docs and the user notes but it's a little unclear. Or is there another 
 reason?

Optional arguments must be given a default value...

function my_func($arg1, $arg2, $arg3, $arg4 = null, $arg5 = null, $arg6 = 
null)

Note that passing a default value by reference was not supported prior to PHP5.

All the relevant details are here: http://php.net/functions.arguments

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

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



Re: Re: [PHP] Variable number of arguments problem

2012-02-12 Thread Tim Streater
On 12 Feb 2012 at 19:01, Stuart Dallas stu...@3ft9.com wrote: 

 Optional arguments must be given a default value...

 function my_func($arg1, $arg2, $arg3, $arg4 = null, $arg5 = null, $arg6 =
 null)

 Note that passing a default value by reference was not supported prior to
 PHP5.

 All the relevant details are here: http://php.net/functions.arguments

Thanks, I do see an example now, although it's not stated explicitly.

--
Cheers  --  Tim

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