Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66722 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11213 invoked from network); 20 Mar 2013 18:15:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Mar 2013 18:15:23 -0000 Received: from [127.0.0.1] ([127.0.0.1:21340]) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ECSTREAM id F1/8A-46127-BBCF9415 for ; Wed, 20 Mar 2013 13:15:23 -0500 Authentication-Results: pb1.pair.com header.from=carlos.vini@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=carlos.vini@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.180 as permitted sender) X-PHP-List-Original-Sender: carlos.vini@gmail.com X-Host-Fingerprint: 74.125.82.180 mail-we0-f180.google.com Received: from [74.125.82.180] ([74.125.82.180:41633] helo=mail-we0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FD/7A-46127-A2BF9415 for ; Wed, 20 Mar 2013 13:08:43 -0500 Received: by mail-we0-f180.google.com with SMTP id k14so1603315wer.25 for ; Wed, 20 Mar 2013 11:08:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:from:date:message-id:subject:to :content-type; bh=pXbrfj+pD7mplwGI6nEXiRvUUl2KbloneoooXgnDjXE=; b=LAvH1r8rAgKKexUVI2iIjDCXWO+vJa0fil0Scs1LEqxBm2JWWgKrmShgwWGFoM0Whi 7w1Um4VVc41no7IL1GTJ3VIbVWMdMGVfeYvRHlGr9nmpVKbB5tqIC+X5jpd2FzYxU6BG AJN1dTbSS8zYiHZKioFTCJP3RLSGGzx8hcqSpjdSDVU9FnESMiSd78k8JjcqbKhD5LII iNrD14qdPKJSenS8Ue6GokEYJz+xEKUY6COH2N6U500V0eafTxDS3WVjICToRrSSZPcu Rw2E9pRvdtK52VqmpQjPYgxr66IYf6WvQgGo5NwHeD2CtqfwQ16HQ+DyFZJwlz6SOJfF h6qQ== X-Received: by 10.194.22.5 with SMTP id z5mr12434079wje.5.1363802920404; Wed, 20 Mar 2013 11:08:40 -0700 (PDT) MIME-Version: 1.0 Received: by 10.194.38.70 with HTTP; Wed, 20 Mar 2013 11:08:20 -0700 (PDT) Date: Wed, 20 Mar 2013 15:08:20 -0300 Message-ID: To: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Subject: Method check - Can someone create a RFC for it? From: carlos.vini@gmail.com (Carlos Rodrigues) Hi, 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. We've had a problem recently where one of our developers forgot an "if". So instead of writing if ($obj->image) { echo $obj->image->getUrl(); } He wrote: echo $obj->image->getUrl(); 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. 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. 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 {}". Examining this problem we happened to stumble open Ruby's and Coffescript's method check. Something like this: $obj->image?->getUrl()?; So my suggestion is: 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. Thanks for reading it. Carlos Rodrigues