Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61466 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 38348 invoked from network); 19 Jul 2012 09:58:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jul 2012 09:58:26 -0000 Authentication-Results: pb1.pair.com header.from=charlie@charliesomerville.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=charlie@charliesomerville.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain charliesomerville.com from 209.85.213.170 cause and error) X-PHP-List-Original-Sender: charlie@charliesomerville.com X-Host-Fingerprint: 209.85.213.170 mail-yx0-f170.google.com Received: from [209.85.213.170] ([209.85.213.170:38837] helo=mail-yx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5B/22-25752-14AD7005 for ; Thu, 19 Jul 2012 05:58:25 -0400 Received: by yenl12 with SMTP id l12so2923058yen.29 for ; Thu, 19 Jul 2012 02:58:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=date:from:to:message-id:in-reply-to:references:subject:x-mailer :mime-version:content-type:x-gm-message-state; bh=m3cNJHHjafFFtZrC3rsCvVSzYpRu6fvi98noFXv6kig=; b=PNqYvg29qzw9eWJ3K1tzdpRBISA2aC9nbZZDwHmSBlLCG0As5OsswmWAKRXpc48/OX C2T8WFy2daND+6jeY6Cb6o0ZUWGYHGm9ZJJNBoQzHn/v9xi5BFGbDEANrFUDRHu+R0FO uexzF158IbSuuIjlpEpGQNCrvVI0aTXY0f2bqGiRKGEEgPiFpxlECoING0LkRd1QXlxm SdgGVcWBOVUEoRtppSMEJT3LLAwkcbqKUbJZsvJxaTX8LHEp6M0hKD21NjHex2DJXUMl F/iFS3uCI6XqKUO/iQIy4ExHQBZNueNOlqLeYvzMsFDWytGNsOxOMBkuNPHEVpOZNh+U 4y8g== Received: by 10.66.78.42 with SMTP id y10mr2587356paw.31.1342691901980; Thu, 19 Jul 2012 02:58:21 -0700 (PDT) Received: from charlies-macbook-pro.fritz.box (124-149-151-83.dyn.iinet.net.au. [124.149.151.83]) by mx.google.com with ESMTPS id ms1sm1486962pbb.63.2012.07.19.02.58.19 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 19 Jul 2012 02:58:21 -0700 (PDT) Date: Thu, 19 Jul 2012 19:58:14 +1000 To: Paul Dragoonis , internals@lists.php.net Message-ID: In-Reply-To: References: <5007D707.2070100@hoa-project.net> X-Mailer: sparrow 1.5 (build 1043.1) MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="5007da36_580bd78f_8327" X-Gm-Message-State: ALoCoQm34K/mLB2d/HoQLWa5K+ZIXjNm6XYth87bCyKraqHvajQ6JbhhMntH5i/DMdstpZtrGbJR Subject: Re: [PHP-DEV] Make try/catch brackets optinal From: charlie@charliesomerville.com (Charlie Somerville) --5007da36_580bd78f_8327 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Thursday, 19 July 2012 at 7:49 PM, Paul Dragoonis wrote: > Why is your try block only going to contain 1 line, and that's > throwing an exception=3F=3F > =20 > try > throw new Exception('foobar'); > catch(Exception =24e) > =20 > =20 Because it's a contrived example. He's not trying to write real code, he'= s trying to demonstrate his point - and you totally missed that point. =20 > 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. > =20 > 1) Braces are good. This is subjective. There are some cases where it might improve code read= ability to drop the braces for a single-statement try/catch. There's certainly no technical barrier to doing this. I'm not familiar wi= th PHP's parser, but I'd imagine there would be some kind of 'statement' = non-terminal that would handle single statements as well as a braced grou= p of statements. > 2) Try with only one line in it to throw an exception doesn't seem > like a realistic situation. > =20 > =20 There could be some utility to this. =46or example, as well as having pos= t-fix if, unless, etc., Ruby also has a post-fix 'rescue'. Here's a silly= example of its use: some=5Fvar =3D foo.bar rescue =22oops=22 If 'foo.bar' threw an exception, some=5Fvar would contain =22oops=22 inst= ead. I think PHP could benefit from having a single statement try form. I ofte= n turn to PHP for quick and dirty scripts when I need to do something wit= h little fuss. I think having try/catch support brace-less single stateme= nts would help increase consistency in PHP's syntax, as well as be useful= in certain situations. =20 On Thursday, 19 July 2012 at 7:49 PM, Paul Dragoonis wrote: > =20 > -1 from me, sorry Hoa. > =20 > On Thu, Jul 19, 2012 at 10:44 AM, Ivan Enderlin =40 Hoa > wrote: > > Hi internals, > > =20 > > As you certainly know, brackets defining blocks in PHP are optional i= f > > blocks contain a single instruction. Thus: > > =20 > > if(=24condition) =7B > > echo 'foobar'; > > =7D > > =20 > > is strictly equivalent to: > > =20 > > if(=24condition) > > echo 'foobar'; > > =20 > > But this syntactic sugar is not applied uniformly to all PHP language= > > constructions. I have the try/catch couple in mind. > > =46irst, I would like to know why it is not possible to write: > > =20 > > try > > throw new Exception('foobar'); > > catch(Exception =24e) > > var=5Fdump(=24e->getMessage()); > > =20 > > as a strict equivalence of: > > =20 > > try =7B > > throw new Exception('foobar'); > > =7D > > catch(Exception =24e) =7B > > var=5Fdump(=24e->getMessage()); > > =7D > > =20 > > Second, if it is possible, could we plan to have this =E2=80=9Cfeatur= e=E2=80=9D (uniformity > > actually) in PHP6 (or maybe before)=3F > > =20 > > Best regards. > > =20 > > -- > > Ivan Enderlin > > Developer of Hoa > > http://hoa.42/ or http://hoa-project.net/ > > =20 > > PhD. student at DISC/=46emto-ST (Vesontio) and INRIA (Cassis) > > http://disc.univ-fcomte.fr/ and http://www.inria.fr/ > > =20 > > Member of HTML and WebApps Working Group of W3C > > http://w3.org/ > > =20 > > =20 > > =20 > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > =20 > =20 > =20 > -- =20 > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > =20 > =20 --5007da36_580bd78f_8327--