Re: 回复: [PHP-DEV] Make try/catch bra ckets optinal

From: Date: Fri, 20 Jul 2012 07:47:51 +0000
Subject: Re: 回复: [PHP-DEV] Make try/catch bra ckets optinal
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-61543@lists.php.net to get a copy of this message
I don't think we should add it purely for consistency, because then we'd have to allow nonsense like: switch x; case 1; endcase; endswitch; or... try; x; catch e; endtry; Sure, consistency is good, but this would allow sloppy code. On Jul 20, 2012 8:36 AM, "Amaury Bouchard" <amaury@amaury.net> wrote: > 2012/7/19 Reeze <reeze.xia@gmail.com> > > > 在 2012年7月19日星期四,下午6:45,Rune Kaagaard 写道: > > > > > +1 for the consistency of it. It's surprising that: > > > > > > if ($foo) > > > return $bar; > > > else > > > return 42; > > > > > > works and: > > > > > > try > > > maybe_dangerous(); > > > catch(Dynamite $e) > > > handle_error(); > > > > > > > > > > There is no condition after try, it's really hard to > > read without > > bracket. > > it becomes even worse if it didn't format pretty as above. > > > > Bad argument. It's not about the presence of a condition after "try". It's > about language consistency. > If you were right, we shouldn't be able to write that: > $i = 0; > do > echo($i++); > while ($i < 3); > > PHP allows it. Nobody cares about it, while I think it's a very ugly > writing. But everybody is accustomed to it, because it's inherited from C > syntax. > And bracketless try/catch doesn't exists in other languages, so it > shouldn't exists in PHP? > > More, do not confuse coding conventions (depends on people, changes from > time to time) and language syntax (should be stable and consistent). >

« previous php.internals (#61543) next »