RFC Karma request: native defer keyword (Zig-style)
| From: | Khaled Alam | Date: | Fri, 26 Dec 2025 15:41:04 +0000 |
| Subject: | RFC Karma request: native defer keyword (Zig-style) | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-129692@lists.php.net to get a copy of this message | ||
Hi, I'm Khaled Alam, a software engineer based in the UAE and a long-time
PHP user. I'd like to request RFC karma to publish an RFC proposing a native
"*defer"* feature and gather community feedback.
Inspired by Zig's "defer", it schedules a block to run when the current
function exits (return, exception, or natural end), executed in LIFO order,
aimed at safer cleanup without repetitive try/finally scaffolding.
Proof-of-concept implementation PR
<https://github.com/php/php-src/pull/20786>.
Current status:
[x] Parser/AST support for defer { ... }
[x] Compilation + VM support with per-call defer stack (not shared on
op_array)
[x] Defers run correctly on explicit/implicit returns, LIFO order
[_] I’m currently working on exception-unwinding handling so defers also run
when an exception is thrown
Wiki username:
*khaledalamxyz*GitHub username*: *khaledalam
Thank you for considering granting RFC karma.
Best regards,
Khaled Alam