Re: C++-like function-try-block proposal
| From: | Alexei Gerasimov | Date: | Sat, 02 Dec 2017 20:08:20 +0000 |
| Subject: | Re: C++-like function-try-block proposal | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-101221@lists.php.net to get a copy of this message | ||
> It would blur the concept of a function body scope, and thus the mental model of how the
> language works.
> E.g. are local variables and parameters shared between the try {} and the catch {} block?
PHP documentation stresses it that the scope is always the entire function, i.e. it isn't like
C/C++ where each compound statement makes up a new scope. The construct may indeed look alien to
those who haven't had experience with C++, however, I believe this is a matter of a single
clarification statement about scope, plus a tip like "just think of it as if wrapping curly
braces are there around it, implicitly" (which is in fact the case), and soon you'll find
yourself comfortable with it.
> It would also mean that userland PHP parsers and IDEs need to support the syntax.
True. However, this is true for pretty much any language change, and PHP has seen quite a few lately
(typehints, anonymous classes.) I don't think we should be worried about changes _other_
projects would have to make to cope up with language evolution lest it becomes an (unnecessary and
surrogate) obstacle. My vision is that if some company/group produces an IDE, it is but natural to
expect them to be ready to adapt to language changes.