3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Closable { public readonly string $key; private bool $closed = false; public function __construct( ?string $key = null, ) { $this->key = uniqid($key ?: 'closable_'); $this->e('__construct'); } private function e(string $out): void { echo $this->key, ': ', $out, "\n"; } public function close(): void { $this->e('close'); $this->e($this->closed ? 'already closed' : 'closing'); $this->closed = true; } public function __destruct() { $this->e('__destruct'); $this->close(); } public static function make(): Closable { return new self(); } } function a(): void { echo "a() start\n"; $a = Closable::make('$a'); echo "a() end\n"; } function b(): void { echo "b() start\n"; $b = Closable::make(); try { if (rand(0,1)) { throw new Exception('b()'); } echo "b() return\n"; unset($b); return; } catch (Exception) { echo "b() catch\n"; } finally { echo "b() finally\n"; isset($b) ? $b->close() : null; } } Closable::make('first'); $foo = Closable::make('$foo'); Closable::make('third'); for ($i = 0; $i <= 10; $i++) { a(); b(); }
Output for git.master_jit
closable_66e940520514d: __construct closable_66e940520514d: __destruct closable_66e940520514d: close closable_66e940520514d: closing closable_66e9405205172: __construct closable_66e9405205176: __construct closable_66e9405205176: __destruct closable_66e9405205176: close closable_66e9405205176: closing a() start closable_66e9405205184: __construct a() end closable_66e9405205184: __destruct closable_66e9405205184: close closable_66e9405205184: closing b() start closable_66e9405205192: __construct b() catch b() finally closable_66e9405205192: close closable_66e9405205192: closing closable_66e9405205192: __destruct closable_66e9405205192: close closable_66e9405205192: already closed a() start closable_66e94052051c0: __construct a() end closable_66e94052051c0: __destruct closable_66e94052051c0: close closable_66e94052051c0: closing b() start closable_66e94052051cf: __construct b() return closable_66e94052051cf: __destruct closable_66e94052051cf: close closable_66e94052051cf: closing b() finally a() start closable_66e94052051de: __construct a() end closable_66e94052051de: __destruct closable_66e94052051de: close closable_66e94052051de: closing b() start closable_66e94052051ec: __construct b() return closable_66e94052051ec: __destruct closable_66e94052051ec: close closable_66e94052051ec: closing b() finally a() start closable_66e94052051fb: __construct a() end closable_66e94052051fb: __destruct closable_66e94052051fb: close closable_66e94052051fb: closing b() start closable_66e9405205209: __construct b() catch b() finally closable_66e9405205209: close closable_66e9405205209: closing closable_66e9405205209: __destruct closable_66e9405205209: close closable_66e9405205209: already closed a() start closable_66e9405205220: __construct a() end closable_66e9405205220: __destruct closable_66e9405205220: close closable_66e9405205220: closing b() start closable_66e940520522e: __construct b() catch b() finally closable_66e940520522e: close closable_66e940520522e: closing closable_66e940520522e: __destruct closable_66e940520522e: close closable_66e940520522e: already closed a() start closable_66e9405205244: __construct a() end closable_66e9405205244: __destruct closable_66e9405205244: close closable_66e9405205244: closing b() start closable_66e9405205252: __construct b() catch b() finally closable_66e9405205252: close closable_66e9405205252: closing closable_66e9405205252: __destruct closable_66e9405205252: close closable_66e9405205252: already closed a() start closable_66e9405205268: __construct a() end closable_66e9405205268: __destruct closable_66e9405205268: close closable_66e9405205268: closing b() start closable_66e9405205276: __construct b() catch b() finally closable_66e9405205276: close closable_66e9405205276: closing closable_66e9405205276: __destruct closable_66e9405205276: close closable_66e9405205276: already closed a() start closable_66e940520528b: __construct a() end closable_66e940520528b: __destruct closable_66e940520528b: close closable_66e940520528b: closing b() start closable_66e9405205299: __construct b() catch b() finally closable_66e9405205299: close closable_66e9405205299: closing closable_66e9405205299: __destruct closable_66e9405205299: close closable_66e9405205299: already closed a() start closable_66e94052052af: __construct a() end closable_66e94052052af: __destruct closable_66e94052052af: close closable_66e94052052af: closing b() start closable_66e94052052bd: __construct b() return closable_66e94052052bd: __destruct closable_66e94052052bd: close closable_66e94052052bd: closing b() finally a() start closable_66e94052052cc: __construct a() end closable_66e94052052cc: __destruct closable_66e94052052cc: close closable_66e94052052cc: closing b() start closable_66e94052052da: __construct b() catch b() finally closable_66e94052052da: close closable_66e94052052da: closing closable_66e94052052da: __destruct closable_66e94052052da: close closable_66e94052052da: already closed a() start closable_66e94052052ef: __construct a() end closable_66e94052052ef: __destruct closable_66e94052052ef: close closable_66e94052052ef: closing b() start closable_66e94052052fd: __construct b() return closable_66e94052052fd: __destruct closable_66e94052052fd: close closable_66e94052052fd: closing b() finally closable_66e9405205172: __destruct closable_66e9405205172: close closable_66e9405205172: closing
Output for git.master
closable_66e9405201359: __construct closable_66e9405201359: __destruct closable_66e9405201359: close closable_66e9405201359: closing closable_66e940520137b: __construct closable_66e940520137f: __construct closable_66e940520137f: __destruct closable_66e940520137f: close closable_66e940520137f: closing a() start closable_66e94052013b1: __construct a() end closable_66e94052013b1: __destruct closable_66e94052013b1: close closable_66e94052013b1: closing b() start closable_66e94052013c3: __construct b() return closable_66e94052013c3: __destruct closable_66e94052013c3: close closable_66e94052013c3: closing b() finally a() start closable_66e94052013d9: __construct a() end closable_66e94052013d9: __destruct closable_66e94052013d9: close closable_66e94052013d9: closing b() start closable_66e94052013e8: __construct b() return closable_66e94052013e8: __destruct closable_66e94052013e8: close closable_66e94052013e8: closing b() finally a() start closable_66e94052013f6: __construct a() end closable_66e94052013f6: __destruct closable_66e94052013f6: close closable_66e94052013f6: closing b() start closable_66e9405201404: __construct b() catch b() finally closable_66e9405201404: close closable_66e9405201404: closing closable_66e9405201404: __destruct closable_66e9405201404: close closable_66e9405201404: already closed a() start closable_66e9405201428: __construct a() end closable_66e9405201428: __destruct closable_66e9405201428: close closable_66e9405201428: closing b() start closable_66e9405201436: __construct b() return closable_66e9405201436: __destruct closable_66e9405201436: close closable_66e9405201436: closing b() finally a() start closable_66e9405201445: __construct a() end closable_66e9405201445: __destruct closable_66e9405201445: close closable_66e9405201445: closing b() start closable_66e9405201453: __construct b() catch b() finally closable_66e9405201453: close closable_66e9405201453: closing closable_66e9405201453: __destruct closable_66e9405201453: close closable_66e9405201453: already closed a() start closable_66e9405201468: __construct a() end closable_66e9405201468: __destruct closable_66e9405201468: close closable_66e9405201468: closing b() start closable_66e9405201475: __construct b() return closable_66e9405201475: __destruct closable_66e9405201475: close closable_66e9405201475: closing b() finally a() start closable_66e9405201484: __construct a() end closable_66e9405201484: __destruct closable_66e9405201484: close closable_66e9405201484: closing b() start closable_66e9405201492: __construct b() catch b() finally closable_66e9405201492: close closable_66e9405201492: closing closable_66e9405201492: __destruct closable_66e9405201492: close closable_66e9405201492: already closed a() start closable_66e94052014a8: __construct a() end closable_66e94052014a8: __destruct closable_66e94052014a8: close closable_66e94052014a8: closing b() start closable_66e94052014b5: __construct b() return closable_66e94052014b5: __destruct closable_66e94052014b5: close closable_66e94052014b5: closing b() finally a() start closable_66e94052014c4: __construct a() end closable_66e94052014c4: __destruct closable_66e94052014c4: close closable_66e94052014c4: closing b() start closable_66e94052014d2: __construct b() return closable_66e94052014d2: __destruct closable_66e94052014d2: close closable_66e94052014d2: closing b() finally a() start closable_66e94052014e0: __construct a() end closable_66e94052014e0: __destruct closable_66e94052014e0: close closable_66e94052014e0: closing b() start closable_66e94052014ed: __construct b() return closable_66e94052014ed: __destruct closable_66e94052014ed: close closable_66e94052014ed: closing b() finally a() start closable_66e94052014fd: __construct a() end closable_66e94052014fd: __destruct closable_66e94052014fd: close closable_66e94052014fd: closing b() start closable_66e940520150a: __construct b() catch b() finally closable_66e940520150a: close closable_66e940520150a: closing closable_66e940520150a: __destruct closable_66e940520150a: close closable_66e940520150a: already closed closable_66e940520137b: __destruct closable_66e940520137b: close closable_66e940520137b: closing
Output for rfc.property-hooks
closable_66e94052051da: __construct closable_66e94052051da: __destruct closable_66e94052051da: close closable_66e94052051da: closing closable_66e9405205200: __construct closable_66e9405205204: __construct closable_66e9405205204: __destruct closable_66e9405205204: close closable_66e9405205204: closing a() start closable_66e9405205211: __construct a() end closable_66e9405205211: __destruct closable_66e9405205211: close closable_66e9405205211: closing b() start closable_66e940520521d: __construct b() catch b() finally closable_66e940520521d: close closable_66e940520521d: closing closable_66e940520521d: __destruct closable_66e940520521d: close closable_66e940520521d: already closed a() start closable_66e9405205243: __construct a() end closable_66e9405205243: __destruct closable_66e9405205243: close closable_66e9405205243: closing b() start closable_66e9405205250: __construct b() return closable_66e9405205250: __destruct closable_66e9405205250: close closable_66e9405205250: closing b() finally a() start closable_66e9405205261: __construct a() end closable_66e9405205261: __destruct closable_66e9405205261: close closable_66e9405205261: closing b() start closable_66e940520526e: __construct b() catch b() finally closable_66e940520526e: close closable_66e940520526e: closing closable_66e940520526e: __destruct closable_66e940520526e: close closable_66e940520526e: already closed a() start closable_66e9405205283: __construct a() end closable_66e9405205283: __destruct closable_66e9405205283: close closable_66e9405205283: closing b() start closable_66e9405205290: __construct b() catch b() finally closable_66e9405205290: close closable_66e9405205290: closing closable_66e9405205290: __destruct closable_66e9405205290: close closable_66e9405205290: already closed a() start closable_66e94052052a3: __construct a() end closable_66e94052052a3: __destruct closable_66e94052052a3: close closable_66e94052052a3: closing b() start closable_66e94052052b0: __construct b() catch b() finally closable_66e94052052b0: close closable_66e94052052b0: closing closable_66e94052052b0: __destruct closable_66e94052052b0: close closable_66e94052052b0: already closed a() start closable_66e94052052c5: __construct a() end closable_66e94052052c5: __destruct closable_66e94052052c5: close closable_66e94052052c5: closing b() start closable_66e94052052d1: __construct b() catch b() finally closable_66e94052052d1: close closable_66e94052052d1: closing closable_66e94052052d1: __destruct closable_66e94052052d1: close closable_66e94052052d1: already closed a() start closable_66e94052052e6: __construct a() end closable_66e94052052e6: __destruct closable_66e94052052e6: close closable_66e94052052e6: closing b() start closable_66e94052052f2: __construct b() return closable_66e94052052f2: __destruct closable_66e94052052f2: close closable_66e94052052f2: closing b() finally a() start closable_66e94052052ff: __construct a() end closable_66e94052052ff: __destruct closable_66e94052052ff: close closable_66e94052052ff: closing b() start closable_66e940520530c: __construct b() return closable_66e940520530c: __destruct closable_66e940520530c: close closable_66e940520530c: closing b() finally a() start closable_66e940520531b: __construct a() end closable_66e940520531b: __destruct closable_66e940520531b: close closable_66e940520531b: closing b() start closable_66e9405205327: __construct b() return closable_66e9405205327: __destruct closable_66e9405205327: close closable_66e9405205327: closing b() finally a() start closable_66e9405205335: __construct a() end closable_66e9405205335: __destruct closable_66e9405205335: close closable_66e9405205335: closing b() start closable_66e9405205343: __construct b() catch b() finally closable_66e9405205343: close closable_66e9405205343: closing closable_66e9405205343: __destruct closable_66e9405205343: close closable_66e9405205343: already closed a() start closable_66e9405205357: __construct a() end closable_66e9405205357: __destruct closable_66e9405205357: close closable_66e9405205357: closing b() start closable_66e9405205364: __construct b() return closable_66e9405205364: __destruct closable_66e9405205364: close closable_66e9405205364: closing b() finally closable_66e9405205200: __destruct closable_66e9405205200: close closable_66e9405205200: closing

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
32.13 ms | 443 KiB | 5 Q