> This has code readability problem written all over it. When maintaining it > also has problems, like with the bracket-less if's. > You would need to add brackets if you add an extra line here, as well as > you might get unexpected behaviour of you forget to > add brackets in that case. > >
I've often heard people make this argument, but I've never found it to be a real concern in practise. Is this really such a common problem? On Thursday, 19 July 2012 at 8:01 PM, Rafael Dohms wrote: > On Thu, Jul 19, 2012 at 11:44 AM, Ivan Enderlin @ Hoa < > [email protected] (mailto:[email protected])> 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. > > > > > Writing if blocks without brakets is considered a bad practice. IMHO anyway. > > > > 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()); > > > > This has code readability problem written all over it. When maintaining it > also has problems, like with the bracket-less if's. > You would need to add brackets if you add an extra line here, as well as > you might get unexpected behaviour of you forget to > add brackets in that case. > > > > 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 “feature” > > (uniformity actually) in PHP6 (or maybe before)? > > > > Sorry, -1 from me. > >
