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

From: Date: Tue, 21 Feb 2012 16:06:17 +0000
Subject: Re: Exceptions for method on non-object rather than fatal (desired feature?)
References: 1 2  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
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. -- Ralf Lang Linux Consultant / Developer Tel.: +49-170-6381563 Mail: [email protected] B1 Systems GmbH Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537

Thread (18 messages)

« previous php.internals (#57917) next »