Using default argument values in the middle of the argument list
| From: | 324706 at mail dot muni dot cz | Date: | Fri, 01 Jun 2012 19:52:06 +0000 |
| Subject: | Using default argument values in the middle of the argument list | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-318089@lists.php.net to get a copy of this message | ||
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