[PHP-BUG] Req #75576 [NEW]: C++-like function-try-blocks
[email protected] ("enclaved at safe-mail dot net") Mon, 27 Nov 2017 02:53:36 GMT
| Newsgroups | php.standards |
|---|---|
| Message-ID | <[email protected]> |
From: enclaved at safe-mail dot net
Operating system: All
PHP version: 7.2Git-2017-11-27 (Git)
Package: PHP Language Specification
Bug Type: Feature/Change Request
Bug description:C++-like function-try-blocks
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 bug report at https://bugs.php.net/bug.php?id=75576&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75576&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75576&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75576&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75576&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75576&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75576&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75576&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75576&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75576&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75576&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75576&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75576&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75576&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75576&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75576&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75576&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75576&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75576&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75576&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75576&r=mysqlcfg