Re: Using default argument values in the middle of the argument list
| From: | marco@behnke.biz | Date: | Mon, 04 Jun 2012 07:10:39 +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-318133@lists.php.net to get a copy of this message | ||
324706@mail.muni.cz hat am 1. Juni 2012 um 21:52 geschrieben:
> 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.
You can find anything on that topic on the type hint section.
If you use type hinting:
Classname $a,
$a can only be instance of Classname, nothing else. But if you want to allow
null as well, you have to write
Classname $a = null,
Don't mistake this as default value! It is _meant_ as "Classname or null" are
allowed.