Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66729 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 24036 invoked from network); 20 Mar 2013 19:09:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Mar 2013 19:09:15 -0000 Authentication-Results: pb1.pair.com header.from=Frank.Liepert@gmx.de; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=frank.liepert@gmx.de; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.de designates 212.227.15.19 as permitted sender) X-PHP-List-Original-Sender: frank.liepert@gmx.de X-Host-Fingerprint: 212.227.15.19 mout.gmx.net Received: from [212.227.15.19] ([212.227.15.19:65483] helo=mout.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CB/2D-46127-5590A415 for ; Wed, 20 Mar 2013 14:09:09 -0500 Received: from mailout-de.gmx.net ([10.1.76.31]) by mrigmx.server.lan (mrigmx001) with ESMTP (Nemesis) id 0MWvJi-1UFDVe1a3o-00VuSz for ; Wed, 20 Mar 2013 20:09:06 +0100 Received: (qmail invoked by alias); 20 Mar 2013 19:09:06 -0000 Received: from p549B3BCB.dip.t-dialin.net (EHLO FrankPC) [84.155.59.203] by mail.gmx.net (mp031) with SMTP; 20 Mar 2013 20:09:06 +0100 X-Authenticated: #18131098 X-Provags-ID: V01U2FsdGVkX18+5Jos2fY+DLg7LtCp2O9YH2hMAf+24TtVmuNwRM 5xm1h+qQJk/d0G To: "'Carlos Rodrigues'" , References: In-Reply-To: Date: Wed, 20 Mar 2013 20:09:08 +0100 Message-ID: <001d01ce259e$669dc840$33d958c0$@Liepert@gmx.de> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Ac4llvQKLKCxCEYqROWleToQsIFKFwAB1eYg Content-Language: de X-Y-GMX-Trusted: 0 Subject: AW: [PHP-DEV] Method check - Can someone create a RFC for it? From: Frank.Liepert@gmx.de ("Frank Liepert") > -----Urspr=FCngliche Nachricht----- > Von: Carlos Rodrigues [mailto:carlos.vini@gmail.com] > Gesendet: Mittwoch, 20. M=E4rz 2013 19:08 > An: internals@lists.php.net > Betreff: [PHP-DEV] Method check - Can someone create a RFC for it? >=20 > Hi, >=20 > I'd like to suggest a new functionality for PHP. I don't know the > internals, and i can't create a patch implementing this. I'm writing > here in case someone likes this idea and write a RFC. >=20 > We've had a problem recently where one of our developers forgot an > "if". >=20 > So instead of writing > if ($obj->image) { > echo $obj->image->getUrl(); > } >=20 > He wrote: > echo $obj->image->getUrl(); >=20 > Here, locally, it was working cause we had the image. But when we > updated the online version we got a "Fatal error: Call to a member > function getUrl() on a non-object" cause someone didn't upload the > image in one of the records that we're on the home page. >=20 > Fatal errors like this can't be catched by a try/catch. And since this > getUrl() was not essential for the page, we'd better output an empty > string then having the site offline. >=20 > One might say: "you guys should have tested it better", or "The image > field should be mandatory in the back end." > And it's true, he should have written that extra "if {}". >=20 > Examining this problem we happened to stumble open Ruby's and > Coffescript's method check. > Something like this: >=20 > $obj->image?->getUrl()?; >=20 > So my suggestion is: >=20 > Create something like $foo->bar?() or $foo->bar()?, where you don't > care whether the function exists, or if $foo is an object. If it > doesn't exist you just return null. > I guess there are plenty of systems out there where it's better to > output an empty string than having your site offline, just cause the > programmer couldn't test it completely. >=20 > Thanks for reading it. >=20 > Carlos Rodrigues >=20 > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php Just one question: Is your developer a template designer?