Re: Re: ClassHints and NULL
| From: | Ray Hilton | Date: | Thu, 17 Jun 2004 13:23:10 +0000 |
| Subject: | Re: Re: ClassHints and NULL | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-10568@lists.php.net to get a copy of this message | ||
I understand your point, however, this is the way that other languages behave and its a feature that i consider to be very necessary and timesaving. My understanding was that Typehinting exists to save having to do such if-else clauses all the time, since 99.9% of the time, you will expect an object of a certain class or nothing at all. The problem here is that i need only to know that an argument is either an instance of a class or null, nothing else, but removing the typehinting effectively means any argument can be passed, and its not longer enforced at a PHP level, but within my own code... and since this is something that happens a lot, it seems a shame to loose this handy, timesaving functionality.
Ray
and Marcus Boerger wrote:
Hello Ray, Wednesday, June 16, 2004, 4:26:26 PM, you wrote:Hi all,[....] - NOTHING stops you from passing NULL to functions. - Typhints are a shortcut for an 'instanceof'`test - now try NULL instanceof stdclass: php-cvs $ php -r 'var_dump(NULL instanceof stdclass);' bool(false) - what you probablywant is function bla($x) { if (is_null($x)) { // handle null } else if ($x instanceof whatever) { // handle instance } else { // handle error } } - if you look again you'll see that you are doing *three different* things in your code. Typehints have a different usage! best regards marcus