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

From: Date: Tue, 21 Feb 2012 17:58:17 +0000
Subject: Re: Exceptions for method on non-object rather than fatal (desired feature?)
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-57922@lists.php.net to get a copy of this message
On 21/02/12 17:06, Ralf Lang wrote: > Am 21.02.2012 16:55, schrieb Martin Amps: >> Could you not implement such functionality within your class as follows: >> >> class Family { >> public function getMother() { >> if ($this->hasMother()) >> return $someObj; >> else >> throw new BadMethodCallException(...); >> } >> } >> >> try { >> $granny_name = $baby->getMother()->getMother()->getName(); >> } catch (BadMethodCallException $ex) { >> >> } >> >> Martin > > Hi Martin, > > First of all, thank you for your rapid response but it doesn't address > my question (or at least the question I intended to ask) > > of course there is always a way to script around issues rather than > adressing them. I just want to know if the change would be desired. I > have code around which does exactly this, check on all levels of all > possible combinations. Semantically, this is nonsense and it bloats > the code. It's just a requirement because currently PHP handles this > as non-recoverable fatal. > > I see no reason why it would be not desirable to have PHP raise the > exception rather than putting more or less repeating code snippets all > around the place. That is why I am asking. You must be returning false/null somewhere. It's the same effor to instead throw an exception or to return a Ghost family member.

« previous php.internals (#57922) next »