From: kriss at krizalys dot com Operating system: * PHP version: 5.4.3 Package: Scripting Engine problem Bug Type: Feature/Change Request Bug description:[PATCH] Add support for alternative try/catch syntax
Description: ------------ The attached patch adds support to alternatively open a try block using a colon (:) in try/catch structures. When using this syntax, each catch block must also be open by a colon, try and catch blocks must not be closed by a closing brace (}), and the whole try/catch structure must be closed by a "endtry" keyword. The idea is to provide greater readability when PHP code is intermixed with HTML code and keep consistency with constructs like if/endif, for/foreach, etc... Please, note that after patching, the Zend scanner and parser, as well as ext/tokenizer_data.c should be regenerated (using re2c, bison and tokenizer_data_gen.sh respectively, or using the provided Makefile targets). Test script: --------------- <?php try: echo "Trying something unsafe\n"; throw new Exception('thrown using alternative try/catch syntax'); catch (int $e): echo "Caught exception of type int (ints are not throwable, this is just example)\n"; // several statements can also be used here catch (Exception $e): echo "Caught exception of type Exception: {$e->getMessage()}\n"; // several statements can also be used here endtry; ?> <?php try:?> <p>Trying something unsafe</p> <?php throw new Exception('thrown using alternative try/catch syntax');?> <?php catch (int $e):?> <p>Caught exception of type int (ints are not throwable, this is just example)</p> <?php catch (Exception $e):?> <p>Caught exception of type Exception: <?php echo $e->getMessage();?></p> <?php endtry;?> Expected result: ---------------- Trying something unsafe Caught exception of type Exception: thrown using alternative try/catch syntax <p>Trying something unsafe</p> <p>Caught exception of type Exception: thrown using alternative try/catch syntax</p> Actual result: -------------- PHP Parse error: syntax error, unexpected ':', expecting '{' in /home/aaa/test.php on line 2 Parse error: syntax error, unexpected ':', expecting '{' in /home/aaa/test.php on line 2 -- Edit bug report at https://bugs.php.net/bug.php?id=62164&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=62164&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=62164&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=62164&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=62164&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=62164&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=62164&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=62164&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=62164&r=needscript Try newer version: https://bugs.php.net/fix.php?id=62164&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=62164&r=support Expected behavior: https://bugs.php.net/fix.php?id=62164&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=62164&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=62164&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=62164&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=62164&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=62164&r=dst IIS Stability: https://bugs.php.net/fix.php?id=62164&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=62164&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=62164&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=62164&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=62164&r=mysqlcfg