Req #75576 [Opn->Sus]: C++-like function-try-blocks
| From: | requinix@php.net | Date: | Mon, 27 Nov 2017 03:05:34 +0000 |
| Subject: | Req #75576 [Opn->Sus]: C++-like function-try-blocks | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-212729@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75576&edit=1
ID: 75576
Updated by: requinix@php.net
Reported by: enclaved at safe-mail dot net
Summary: C++-like function-try-blocks
-Status: Open
+Status: Suspended
Type: Feature/Change Request
-Package: PHP Language Specification
+Package: Scripting Engine problem
Operating System: All
PHP Version: 7.2Git-2017-11-27 (Git)
Block user comment: N
Private report: N
New Comment:
Thank you for your interest in PHP and for submitting a feature
request. Please be aware that due to the magnitude of change this
request requires, it would be necessary to discuss it on PHP
Internals list (internals@lists.php.net) as an RFC. Please read
the guide about creating RFCs here:
<https://wiki.php.net/rfc/howto>. If you
haven't had experience
with writing RFCs before, it is advised to seek guidance on the
Internals list (<http://php.net/mailing-lists.php>) and/or solicit
help from one of the experienced developers.
Please do not consider this comment as a negative view on the
merits of your proposal â every proposal which requires changes of
certain magnitude, even the very successful and widely supported
ones, must be done through the RFC process. This helps make the
process predictable, transparent and accessible to all developers.
Previous Comments:
------------------------------------------------------------------------
[2017-11-27 02:53:34] enclaved at safe-mail dot net
Description:
------------
I am proposing a patch to bring C++-like function-try-block shorthand syntax for whole-function
try-catch-finally blocks:
function fuu($foo, $bar): void try
{
may_throw($foo);
may_throw($bar);
} catch (FuuException $e) {
echo $e->getMessage();
}
The proposed patch is attached. It makes purely cosmetic modifications to zend_language_parser.y
grammar to augment plain functions, class methods, and closures to accept try-catch-finally blocks
as their bodies in addition to regular compound statements. It amounts to just a handful of lines
and entails no API changes.
Test script:
---------------
function coyote(bool $acme): void try
{
echo "Coyote";
if ($acme) {
throw new RuntimeException;
}
} catch (RuntimeException $e) {
/*
* Coyote succeeds.
*/
} finally {
if (empty($e)) {
echo " never";
}
echo " catches Roadrunner", PHP_EOL;
}
coyote(false);
coyote(true);
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75576&edit=1