On 2012-07-19, "Ivan Enderlin @ Hoa" <ivan.ender...@hoa-project.net> wrote:
> 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 “feature” 
> (uniformity actually) in PHP6 (or maybe before)?

I'd hesitate to call this a feature. If anything, for PHP6, I'd
recommend the opposite:  getting rid of brace-less blocks, period.

I've read through the thread, and those proposing it talk about code
readability, and use the argument "I've never had a problem before." To
me, this means you've either (a) not been developing very long, and/or
(b) not been working in long-lived projects, and/or (c) do not work with
other people. Omitting braces makes understanding the intent of the
code harder (did the author intend to only execute one statement, or did
they forget the braces?), makes maintenance harder (a developer needing
to add extra statements now also has to add the braces), and leads to
hard-to-detect bugs (see previous two points).

I've run into problems with brace-less blocks many, many times over
the years. Clearly, enough other people have as well that any serious
coding standard includes a clause requiring that all blocks use
braces. I see no reason to add another context in which braces could
be omitted.

-- 
Matthew Weier O'Phinney
Project Lead            | matt...@zend.com
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to