aboutsummaryrefslogtreecommitdiff
path: root/include/defer.php
diff options
context:
space:
mode:
authorMathias Magnusson <mathias@magnusson.space>2025-09-22 21:25:49 +0200
committerMathias Magnusson <mathias@magnusson.space>2025-09-22 21:25:49 +0200
commita2827963fbf6847166360be635c65dc85d20dd0d (patch)
tree3904f4a24733c4e097eb4baba4283973e5dabdbd /include/defer.php
parentfb59ea2f57da2abf3c7bd76feddfaf10e109d2f4 (diff)
downloadtraedgaardstomten-a2827963fbf6847166360be635c65dc85d20dd0d.tar.gz
PHP FTW!
Diffstat (limited to 'include/defer.php')
-rw-r--r--include/defer.php12
1 files changed, 12 insertions, 0 deletions
diff --git a/include/defer.php b/include/defer.php
new file mode 100644
index 0000000..ee01bbc
--- /dev/null
+++ b/include/defer.php
@@ -0,0 +1,12 @@
+<?php
+
+function defer(&$context, $f): void {
+ $context ??= new class() {
+ public $funcs = [];
+ public function __destruct()
+ {
+ while (count($this->funcs)) array_pop($this->funcs)();
+ }
+ };
+ $context->funcs[] = $f;
+}