On Sun, Nov 26, 2017 at 11:06 PM, <enclaved@safe-mail.net> wrote:
> I am proposing a patch (see attachment)
>
php.net mailing lists don't like attachments (virus paranoia and
similar). If you have a patch, the best thing to do is submit it as a
PR on github. Then, we can all link to parts and add comments and
it's generally a better place to discuss implementation.
> to bring C++-like function-try-block
> shorthand syntax (http://en.cppreference.com/w/cpp/language/function-try-block)
> for whole-function try-catch-finally blocks:
>
It's a pretty minor bit of syntactic sugar that I use in C++
occasionally and it can reduce cognitive overhead by some fraction of
a percent at the cost of a little extra complexity in the parser and
no compiler/runtime changes. Overall I'm only +0 on it as it does add
complexity to the parser for a very very tiny benefit.
Consider the following already legal syntax:
function fuu($foo, $bar): void {try
{
may_throw($foo);
may_throw($bar);
} catch (FuuException $e) {
echo $e->getMessage();
}}
Same effect and very nearly same visual scan as the block you pasted,
but with no need for additional syntax.
> Since PHP is partially influenced by C++, I believe this syntax would be
> a meaningful step in making PHP a little bit more intuitively compatible
> with C++ practices, which may prove useful for people who come to PHP from
> the C++ world (such as myself.) The expected benefit is PHP becomes yet
> more familiar and comfortable for C++ programmers.
>
I'm not sure this statement is entirely accurate. PHP's fundamental
inspirations come from perl and C. It's OOP layer was inspired in
part from C++, but also from Java. This mixed ancestry doesn't
necessarily indicate a push toward any one of those syntaxes. PHP is
PHP, it's best when it steals the parts of other languages which make
sense for it to steal.
> I submitted my patch via the bugtracker: https://bugs.php.net/bug.php?id=75576
>
Ah, disregard my initial comment above then (though PRs do have advantages).
At a glance, your patch makes sense. 👍
-Sara