Re: Exceptions for method on non-object rather than fatal (desired feature?)

From: Date: Wed, 22 Feb 2012 19:04:20 +0000
Subject: Re: Exceptions for method on non-object rather than fatal (desired feature?)
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On 2/22/12 12:37 PM, Peter Lind wrote:

I would also support this. There's a myriad reasons why something may
return NULL or FALSE when you expect it to return an object, some of them even legitimate. Any function/method whose documentation line is "returns the foo object, or NULL if someone screwed up and there isn't one" is perfectly reasonable in many cases, IMO, but makes all chains a potential fatal. An exception would make a lot more sense, and allow us to centralize handling of such "exceptional" cases rather than throwing if-checks everywhere. (Which is exactly what exceptions are for.)
--Larry Garfield -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Seems to me this change would encourage bad habits (breaking the law of Demeter) which would personally put me against it. Regards Peter
How? What bad habit does this encourage? --Larry Garfield

Thread (18 messages)

« previous php.internals (#57956) next »