Re: Type hints with null default values
| From: | Jason Garber | Date: | Tue, 19 Oct 2004 00:06:37 +0000 |
| Subject: | Re: Type hints with null default values | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-13376@lists.php.net to get a copy of this message | ||
Hello,
Consider this: public function foo(MyClass $o)
If you allow null, false, or anything else, you must CHECK it before
using it or you will get a "calling a method on a non-object" first.
The whole point of having a type hint, from my point of view, is so
the majority of time I DO NOT have to check the incoming parameter
before using it.
If nulls or false's are allowed, without explicitly saying they are,
such as function foo(nullable MyClass $o), then I'll have to either
do an is_null() or instanceof check on each parameter.
I'm all for it if we have an option added to the function syntax
such as nullable, but otherwise, it's usefulness is minimized.
--
Best regards,
Jason mailto:jason@ionzoft.com