rfc:non-capturing_catches
Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
rfc:non-capturing_catches [2020/04/06 08:37] maxsem ++ |
rfc:non-capturing_catches [2020/05/26 14:39] (current) maxsem implemented |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== PHP RFC: Your Title Here ====== | + | ====== PHP RFC: non-capturing catches |
* Version: 0.9 | * Version: 0.9 | ||
* Date: 2020-04-05 | * Date: 2020-04-05 | ||
* Author: Max Semenik < | * Author: Max Semenik < | ||
- | * Status: | + | * Status: |
+ | * Implementation: | ||
* First Published at: https:// | * First Published at: https:// | ||
===== Introduction ===== | ===== Introduction ===== | ||
Currently, PHP requires to capture the exception being caught to a variable: | Currently, PHP requires to capture the exception being caught to a variable: | ||
- | <php> | + | <code php> |
try { | try { | ||
foo(); | foo(); | ||
Line 14: | Line 15: | ||
die($ex-> | die($ex-> | ||
} | } | ||
- | </php> | + | </code> |
However, you need to specify the variable even if it's not used: | However, you need to specify the variable even if it's not used: | ||
- | <php> | + | |
+ | <code php> | ||
try { | try { | ||
changeImportantData(); | changeImportantData(); | ||
Line 22: | Line 25: | ||
echo "You don't have permission to do this"; | echo "You don't have permission to do this"; | ||
} | } | ||
- | </php> | + | </code> |
Someone reading the above code is left to wonder if the author intended to not use the exception variable or it's a bug. | Someone reading the above code is left to wonder if the author intended to not use the exception variable or it's a bug. | ||
===== Proposal ===== | ===== Proposal ===== | ||
Allow catching exceptions without capturing them to variables: | Allow catching exceptions without capturing them to variables: | ||
- | <php> | + | <code php> |
try { | try { | ||
changeImportantData(); | changeImportantData(); | ||
Line 33: | Line 37: | ||
echo "You don't have permission to do this"; | echo "You don't have permission to do this"; | ||
} | } | ||
- | </php> | + | </code> |
===== Prior art ===== | ===== Prior art ===== | ||
+ | Such change was first proposed in [[https:// | ||
+ | <code php> | ||
+ | try { | ||
+ | foo(); | ||
+ | } catch { | ||
+ | bar(); | ||
+ | } | ||
+ | </ | ||
+ | Meanwhile what I'm proposing here has received mostly positive feedback so I feel it's worth revisiting. | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 46: | Line 59: | ||
None. | None. | ||
- | ===== Open Issues | + | ===== Vote ===== |
- | Make sure there are no open issues when the vote starts! | + | Voting started on 2020-05-10 and will end on 2020-05-24 at 9:00 UTC. |
- | + | <doodle title=" | |
- | ===== Proposed Voting Choices ===== | + | * Yes |
- | Include these so readers know where you are heading and can discuss the proposed voting options. | + | * No |
+ | </ | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
- | * https:// | + | * https:// |
===== Implementation ===== | ===== Implementation ===== | ||
Line 63: | Line 77: | ||
===== References ===== | ===== References ===== | ||
- | Links to external references, discussions or RFCs | + | * https:// |
===== Rejected Features ===== | ===== Rejected Features ===== | ||
Keep this updated with features that were discussed on the mail lists. | Keep this updated with features that were discussed on the mail lists. |
rfc/non-capturing_catches.1586162244.txt.gz · Last modified: 2020/04/06 08:37 by maxsem