Re: Type hints with null default values
| From: | Ron Korving | Date: | Mon, 18 Oct 2004 08:39:44 +0000 |
| Subject: | Re: Type hints with null default values | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-13371@lists.php.net to get a copy of this message | ||
> Robert Silva wrote:
> What I propose is something like:
>
> if the typehinted parameter is optional and the user doesn't pass it, the
> only "type" it can have (at least now) is "null". So, if you, as a
> developer, want a function to have optional typehinted parameters, you
must
> check for null to test if the user passed the parameter or not, IMHO it's
> logical.
>
> function f(Obj $a, Obj $b=null, Obj $c=null) {...}
> You can't call f(null) since the first argument is mandatory, typehinted
and
> doesn't allow nulls, but you can call f(new Obj(), null, new Obj()) since
> the second argument is optional and allow nulls(the notation =null).
I totally agree with you. IMHO this is exactly how it should work. I've
actually been waiting for this feature for a while now, so I'm glad the
discussion is active again.
Ron