aboutsummaryrefslogtreecommitdiff
path: root/include/defer.php
blob: ee01bbcbc2c7f4f917debe87320ca14f8a1b6a20 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
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;
}