|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
Patchesfunc-try-block (last revision 2017-11-27 02:54 UTC by enclaved at safe-mail dot net)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-11-27 03:05 UTC] requinix@php.net
-Status: Open
+Status: Suspended
-Package: PHP Language Specification
+Package: Scripting Engine problem
[2017-11-27 03:05 UTC] requinix@php.net
[2017-11-27 03:12 UTC] stas@php.net
-Status: Suspended
+Status: Open
[2017-11-27 03:12 UTC] stas@php.net
[2017-11-27 03:12 UTC] stas@php.net
-Status: Open
+Status: Suspended
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 04:00:01 2025 UTC |
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);