Re: Using default argument values in the middle of the argument list
| From: | Matijn Woudt | Date: | Sat, 02 Jun 2012 15:13:55 +0000 |
| Subject: | Re: Using default argument values in the middle of the argument list | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-318102@lists.php.net to get a copy of this message | ||
On Fri, Jun 1, 2012 at 9:52 PM, <324706@mail.muni.cz> wrote:
> Hi,
>
> as I accidentally found out that PHP allows default argument values
> to occur not only at the end of parameter list:
>
> function ( Classname $a, Classname $b = null, Classname $c ) ...
>
> Unfortunately, documentation does not state what is supposed to happen in
> such situation.
> It appears $b can be an instance of Classname or a null.
>
> I've draw up simple test case (https://gist.github.com/2829626) to verify my
> assumption
> and it seems to work at least since PHP 5.3.0. It is extremely useful to
> allow null
> value and retain the power of type hints at the same time.
>
> Is there anything else to test? Does it work for your setup? Can it be used
> that way?
> And if yes, can it be officially documented?
>
> Do not hesitate to prove I'm wrong.
>
> -- Oliver
>
Hi Oliver,
I think the example at [1] demonstrates that it is possible, but it
also notes that it is pretty useless. Why are you interested in this?
- Matijn
[1] http://www.php.net/manual/en/functions.arguments.php#example-153