diff options
| author | Mathias Magnusson <mathias@magnusson.space> | 2025-09-22 21:25:49 +0200 |
|---|---|---|
| committer | Mathias Magnusson <mathias@magnusson.space> | 2025-09-22 21:25:49 +0200 |
| commit | a2827963fbf6847166360be635c65dc85d20dd0d (patch) | |
| tree | 3904f4a24733c4e097eb4baba4283973e5dabdbd /include/defer.php | |
| parent | fb59ea2f57da2abf3c7bd76feddfaf10e109d2f4 (diff) | |
| download | traedgaardstomten-a2827963fbf6847166360be635c65dc85d20dd0d.tar.gz | |
PHP FTW!
Diffstat (limited to 'include/defer.php')
| -rw-r--r-- | include/defer.php | 12 |
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; +} |
