php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #75576 C++-like function-try-blocks
Submitted: 2017-11-27 02:53 UTC Modified: 2017-11-27 03:12 UTC
From: enclaved at safe-mail dot net Assigned:
Status: Suspended Package: Scripting Engine problem
PHP Version: 7.2Git-2017-11-27 (Git) OS: All
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2017-11-27 02:53 UTC] 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);


Patches

func-try-block (last revision 2017-11-27 02:54 UTC by enclaved at safe-mail dot net)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [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
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.
 [2017-11-27 03:12 UTC] stas@php.net
-Status: Suspended +Status: Open
 [2017-11-27 03:12 UTC] stas@php.net
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 to 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.
 [2017-11-27 03:12 UTC] stas@php.net
-Status: Open +Status: Suspended
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 15:01:29 2024 UTC