Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66742 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39382 invoked from network); 21 Mar 2013 23:41:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Mar 2013 23:41:30 -0000 Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.210.48 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.210.48 mail-da0-f48.google.com Received: from [209.85.210.48] ([209.85.210.48:49036] helo=mail-da0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 74/20-35504-9AA9B415 for ; Thu, 21 Mar 2013 18:41:30 -0500 Received: by mail-da0-f48.google.com with SMTP id p8so1909868dan.35 for ; Thu, 21 Mar 2013 16:41:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:references:mime-version:in-reply-to:content-type :content-transfer-encoding:message-id:cc:x-mailer:from:subject:date :to; bh=Shrd5EdewYX8G6C3XFw/lxGFCZ1DourMdYIX0fZtgkk=; b=HRYgzqAUXs2KtVen+6b149mYQVs35D+BMzXgs8te9Hkm4J5L1tF+dA9d/Zo4IQIxyW gI7+5njtInjxMnxu4e9UzGompPGwxa/MKZOLAbS9FEanyqTKykomIb39LyE6DRjQCwST PfAVcjhrCtwDx6uysotF6WsFdF7UGNswA1xiOJOxLJKU4nsa+rLFy57sxWkJrrgUDB+I GuU7iDvSWuOOpE2ClGM90COK7OkxUgLsy5IYCoubYHM2RHutsB/RZ/J5dVml3oHbFD0B /wKN3ylkOBpxSGu6SQX3K4oY7b27qq1pzZ5fmvcHsvPUYkOdopBEKVO1JJ2aKy3aLU3h ojMA== X-Received: by 10.68.129.163 with SMTP id nx3mr17512569pbb.13.1363909286484; Thu, 21 Mar 2013 16:41:26 -0700 (PDT) Received: from [192.168.1.104] (bb42-60-19-235.singnet.com.sg. [42.60.19.235]) by mx.google.com with ESMTPS id ol7sm8062pbb.14.2013.03.21.16.41.24 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 21 Mar 2013 16:41:25 -0700 (PDT) References: Mime-Version: 1.0 (1.0) In-Reply-To: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Message-ID: <7C4ECDFD-7DB4-469E-B79F-09903228D326@gmail.com> Cc: "internals@lists.php.net" X-Mailer: iPhone Mail (10B146) Date: Fri, 22 Mar 2013 07:41:22 +0800 To: Carlos Rodrigues Subject: Re: [PHP-DEV] Method check - Can someone create a RFC for it? From: tjerk.meesters@gmail.com (Tjerk Meesters) On 21 Mar, 2013, at 2:08 AM, Carlos Rodrigues wrote:= > 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. You can register a shutdown function with register_shutdown_function() and c= heck for error_get_last() inside.=20 In most cases you can't really handle this particular error very well anyway= . At least with this you can have the full error emailed to you if you wish a= nd print some kind of error message on the page.=20 >=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 > --=20 > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >=20