Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66728 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22299 invoked from network); 20 Mar 2013 19:06:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Mar 2013 19:06:00 -0000 Authentication-Results: pb1.pair.com header.from=johannes@schlueters.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=johannes@schlueters.de; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain schlueters.de from 217.114.211.66 cause and error) X-PHP-List-Original-Sender: johannes@schlueters.de X-Host-Fingerprint: 217.114.211.66 config.schlueters.de Received: from [217.114.211.66] ([217.114.211.66:52647] helo=config.schlueters.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 18/CC-46127-6980A415 for ; Wed, 20 Mar 2013 14:05:59 -0500 Received: from transformer.fritz.box (ppp-188-174-39-120.dynamic.mnet-online.de [188.174.39.120]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client did not present a certificate) by config.schlueters.de (Postfix) with ESMTPSA id 7B99C65581; Wed, 20 Mar 2013 20:05:55 +0100 (CET) User-Agent: K-9 Mail for Android In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Date: Wed, 20 Mar 2013 20:05:58 +0100 To: Carlos Rodrigues ,internals@lists.php.net Message-ID: <42394b81-ce69-45ea-b383-74dcd365b2d4@email.android.com> Subject: Re: [PHP-DEV] Method check - Can someone create a RFC for it? From: johannes@schlueters.de (=?ISO-8859-1?Q?Johannes_Schl=FCter?=) Carlos Rodrigues wrote: >So instead of writing >if ($obj->image) { >echo $obj->image->getUrl(); >} > >He wrote: >echo $obj->image->getUrl(); Make the property private and add a getter which can throw an exception if no image is available ... class C { private $image; public function hasImage() { return (bool)$this->image; } public function getImage() { if (!$this->image) { throw new NoImageException(); } return $this->image; } } echo $obj->geImage()->getUrl(); // Exception which can be caught. No nee dto change the language and add a new cosntruct (which your developer will forget, if he forgets the if already ....) johannes