Re: [RFC] Type hints
| From: | Christian Schneider | Date: | Tue, 11 May 2004 13:10:55 +0000 |
| Subject: | Re: [RFC] Type hints | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-9814@lists.php.net to get a copy of this message | ||
Jason Garber wrote:
public static function forName($name, $c = NULL) {
if(is_null($c))
//...
elseif($c instanceof ClassLoader)
//...
else
//Throw an error
Error handling can be boring/tricky/cluttering and that's why most people will simply omit it or die() here. It's basically dead code which is A Bad Thing IMHO.
I think
function forName($name, ClassLoader $classloader = NULL)
{
if (!$classloader)
$classloader = new ClassLoader;
...
}
would be much nicer, doesn't have error handling bloat and is as safe.
All we'd need is to ignore the type hint for the default value. Simple, easy to understand and also safe as the two are close to each other (the same line) so no danger of discrepancy here. IMHO :-)
But I got to the conclusion that as long as we don't introduce a new keyword/syntax for allowing/disallowing null I'm happy :-)
Over and out,
- Chris