Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61471 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 44887 invoked from network); 19 Jul 2012 10:05:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jul 2012 10:05:04 -0000 Authentication-Results: pb1.pair.com smtp.mail=listas@rafaeldohms.com.br; spf=fail; sender-id=fail Authentication-Results: pb1.pair.com header.from=listas@rafaeldohms.com.br; sender-id=fail Received-SPF: fail (pb1.pair.com: domain rafaeldohms.com.br does not designate 209.85.220.170 as permitted sender) X-PHP-List-Original-Sender: listas@rafaeldohms.com.br X-Host-Fingerprint: 209.85.220.170 mail-vc0-f170.google.com Received: from [209.85.220.170] ([209.85.220.170:63822] helo=mail-vc0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 23/B3-25752-ECBD7005 for ; Thu, 19 Jul 2012 06:05:02 -0400 Received: by vcbgb30 with SMTP id gb30so1127834vcb.29 for ; Thu, 19 Jul 2012 03:04:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:x-gm-message-state; bh=dF2QNHiSQ+aSDs1IlmVOxFczcXMUCRH+jzc0cgcom3w=; b=kq4bm9yCq6KuhH5JztsXgtm1PB5y8ZZ2Qa5hTfKB7Y94x3CcoQDfvYc7CZMI2EGNTy vFzgqbwTiTmXSJopkBMdSpLRwIL4poCiVjT+gaecn4CmOSV3UZ7fJO2IzZQqhQNSpl// UKYHlyhdiVn8DGfMwfwP7bd4kYehMts8zVrW5ARfiXJefuE2BrUPyOHijILWnutZr7s3 T4zwZdew5jb+W9D5wRIEW/snZufyE2JyCgDpTrvw5Whvj6OhHcoM75xA+BcgsIictfvh RXg6gEQvwXIraQ8M4ho2bw+bFstvIAUpEiRzKAlBvg8C45xJkPvrJ/O0LZa5lTjMaSoc BnFA== MIME-Version: 1.0 Received: by 10.52.178.170 with SMTP id cz10mr538201vdc.44.1342692298919; Thu, 19 Jul 2012 03:04:58 -0700 (PDT) Received: by 10.220.46.13 with HTTP; Thu, 19 Jul 2012 03:04:58 -0700 (PDT) In-Reply-To: References: <5007D707.2070100@hoa-project.net> Date: Thu, 19 Jul 2012 12:04:58 +0200 Message-ID: To: Charlie Somerville Cc: Paul Dragoonis , internals@lists.php.net Content-Type: multipart/alternative; boundary=bcaec5196461850f0904c52be9ab X-Gm-Message-State: ALoCoQnRI/BwkXTMlf1D1S6pcwP74KcX71YywNXyf7F+kTcICglR6oSCQHw20ZulGNCzeuAwivZd Subject: Re: [PHP-DEV] Make try/catch brackets optinal From: listas@rafaeldohms.com.br (Rafael Dohms) --bcaec5196461850f0904c52be9ab Content-Type: text/plain; charset=ISO-8859-1 On Thu, Jul 19, 2012 at 11:58 AM, Charlie Somerville < charlie@charliesomerville.com> wrote: > > 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?? > > > > try > > throw new Exception('foobar'); > > catch(Exception $e) > > > > > > 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. > > In this case the removal of brackets would surely limit this to one line, so any examples or use cases would look the same. > > 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. > This is subjective. There are some cases where it might improve code > readability to drop the braces for a single-statement try/catch. > > It would cause code maintainability problems and unexpected outputs in error cases, just like if's do. > > There's certainly no technical barrier to doing this. I'm not familiar > with 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 group > of statements. > > > 2) Try with only one line in it to throw an exception doesn't seem > > like a realistic situation. > > > > > > There could be some utility to this. For example, as well as having > post-fix if, unless, etc., Ruby also has a post-fix 'rescue'. Here's a > silly example of its use: > > > some_var = foo.bar rescue "oops" > > If 'foo.bar' threw an exception, some_var would contain "oops" instead. > a rescue method is a complete other thing, sounds interesting, but has no reference to bracket-less try blocks. > > I think PHP could benefit from having a single statement try form. I often > turn to PHP for quick and dirty scripts when I need to do something with > little fuss. I think having try/catch support brace-less single statements > would help increase consistency in PHP's syntax, as well as be useful in > certain situations. > I think bracket-less is a bad practice that was left for BC, i would rather we move away from it then move more things into it. -- Rafael Dohms PHP Evangelist and Community Leader http://www.rafaeldohms.com.br http://www.phpsp.org.br --bcaec5196461850f0904c52be9ab--