Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61469 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42196 invoked from network); 19 Jul 2012 10:03:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jul 2012 10:03:19 -0000 Authentication-Results: pb1.pair.com smtp.mail=krebs.seb@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=sebastian.krebs.berlin@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.170 as permitted sender) X-PHP-List-Original-Sender: krebs.seb@gmail.com X-Host-Fingerprint: 209.85.212.170 mail-wi0-f170.google.com Received: from [209.85.212.170] ([209.85.212.170:35319] helo=mail-wi0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 90/13-25752-56BD7005 for ; Thu, 19 Jul 2012 06:03:18 -0400 Received: by wibhq12 with SMTP id hq12so4629626wib.5 for ; Thu, 19 Jul 2012 03:03:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:x-google-sender-delegation:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to :content-type; bh=5a+Sn2s+R4tE11Oe10do6I1WekSyJT0M4wJ7B6Q7hMQ=; b=eFOOBODFZ40gndoAcTybv7+VyumsHmFsHHQv/j/R5Fzi+Jho2rOn7BCexp+oLWH06B e8oWYaDswr57u+wMWnuIAowldFC5bsSRAhd0NTbUvzrWJEoE8smLigwixrXEmuyACQVM awdLAIYX62c2YHoyxyykkniH2LU6edlOyzTamz5Qtp7uMFgxMBxTG21/hVrIa1GVAc4J r7ofTcDu/3aQr5toAcFih95MnoU4wMbjhBFPT7C9EpVh1vQ8hYSq24B5Ff3Vau/K5fQt 4N0HnGMMMLKO/fy05o5F0cCj2YcbljazKQwy+00lTgHGRKRlLXUemL+KVzC6d3j/nnBd PMIQ== MIME-Version: 1.0 Received: by 10.180.82.39 with SMTP id f7mr3248475wiy.2.1342692194767; Thu, 19 Jul 2012 03:03:14 -0700 (PDT) Sender: sebastian.krebs.berlin@gmail.com X-Google-Sender-Delegation: sebastian.krebs.berlin@gmail.com Received: by 10.14.134.201 with HTTP; Thu, 19 Jul 2012 03:03:14 -0700 (PDT) In-Reply-To: References: <5007D707.2070100@hoa-project.net> Date: Thu, 19 Jul 2012 12:03:14 +0200 X-Google-Sender-Auth: C8AEbK5YA84b9fojen__asjoXRo Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary=f46d041826ea4fd34904c52be33c Subject: Re: [PHP-DEV] Make try/catch brackets optinal From: krebs.seb@gmail.com (Sebastian Krebs) --f46d041826ea4fd34904c52be33c Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Hi, 2012/7/19 Paul Dragoonis > Why is your try block only going to contain 1 line, and that's > throwing an exception?? > > try > throw new Exception('foobar'); > catch(Exception $e) > > > Braces are a good thing, they give structure and stop people from > mis-reading things and writing bugs, the same can be said for the if() > situation. > > 1) Braces are good. > 2) Try with only one line in it to throw an exception doesn't seem > like a realistic situation. > try $this->foobar(); catch ($e) { // Much amount of error handling } // or maybe try $this->foobar(); catch ($e) $this->handleException($e); OK, the first example is better, but both reads like quite nice :) try someVeryDifficultStuff(); catch ($e) { /* handle */ } Regards, Sebastian > > -1 from me, sorry Hoa. > > On Thu, Jul 19, 2012 at 10:44 AM, Ivan Enderlin @ Hoa > wrote: > > Hi internals, > > > > As you certainly know, brackets defining blocks in PHP are optional if > > blocks contain a single instruction. Thus: > > > > if($condition) { > > echo 'foobar'; > > } > > > > is strictly equivalent to: > > > > if($condition) > > echo 'foobar'; > > > > But this syntactic sugar is not applied uniformly to all PHP language > > constructions. I have the try/catch couple in mind. > > First, I would like to know why it is not possible to write: > > > > try > > throw new Exception('foobar'); > > catch(Exception $e) > > var_dump($e->getMessage()); > > > > as a strict equivalence of: > > > > try { > > throw new Exception('foobar'); > > } > > catch(Exception $e) { > > var_dump($e->getMessage()); > > } > > > > Second, if it is possible, could we plan to have this =93feature=94 > (uniformity > > actually) in PHP6 (or maybe before)? > > > > Best regards. > > > > -- > > Ivan Enderlin > > Developer of Hoa > > http://hoa.42/ or http://hoa-project.net/ > > > > PhD. student at DISC/Femto-ST (Vesontio) and INRIA (Cassis) > > http://disc.univ-fcomte.fr/ and http://www.inria.fr/ > > > > Member of HTML and WebApps Working Group of W3C > > http://w3.org/ > > > > > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --f46d041826ea4fd34904c52be33c--