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('$b'); 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_66e9408104975: __construct closable_66e9408104975: __destruct closable_66e9408104975: close closable_66e9408104975: closing closable_66e940810499b: __construct closable_66e940810499f: __construct closable_66e940810499f: __destruct closable_66e940810499f: close closable_66e940810499f: closing a() start closable_66e94081049af: __construct a() end closable_66e94081049af: __destruct closable_66e94081049af: close closable_66e94081049af: closing b() start closable_66e94081049bd: __construct b() return closable_66e94081049bd: __destruct closable_66e94081049bd: close closable_66e94081049bd: closing b() finally a() start closable_66e94081049d3: __construct a() end closable_66e94081049d3: __destruct closable_66e94081049d3: close closable_66e94081049d3: closing b() start closable_66e94081049e1: __construct b() return closable_66e94081049e1: __destruct closable_66e94081049e1: close closable_66e94081049e1: closing b() finally a() start closable_66e94081049f0: __construct a() end closable_66e94081049f0: __destruct closable_66e94081049f0: close closable_66e94081049f0: closing b() start closable_66e94081049fe: __construct b() return closable_66e94081049fe: __destruct closable_66e94081049fe: close closable_66e94081049fe: closing b() finally a() start closable_66e9408104a0d: __construct a() end closable_66e9408104a0d: __destruct closable_66e9408104a0d: close closable_66e9408104a0d: closing b() start closable_66e9408104a1b: __construct b() return closable_66e9408104a1b: __destruct closable_66e9408104a1b: close closable_66e9408104a1b: closing b() finally a() start closable_66e9408104a2a: __construct a() end closable_66e9408104a2a: __destruct closable_66e9408104a2a: close closable_66e9408104a2a: closing b() start closable_66e9408104a38: __construct b() catch b() finally closable_66e9408104a38: close closable_66e9408104a38: closing closable_66e9408104a38: __destruct closable_66e9408104a38: close closable_66e9408104a38: already closed a() start closable_66e9408104a5d: __construct a() end closable_66e9408104a5d: __destruct closable_66e9408104a5d: close closable_66e9408104a5d: closing b() start closable_66e9408104a6b: __construct b() return closable_66e9408104a6b: __destruct closable_66e9408104a6b: close closable_66e9408104a6b: closing b() finally a() start closable_66e9408104a7a: __construct a() end closable_66e9408104a7a: __destruct closable_66e9408104a7a: close closable_66e9408104a7a: closing b() start closable_66e9408104a88: __construct b() catch b() finally closable_66e9408104a88: close closable_66e9408104a88: closing closable_66e9408104a88: __destruct closable_66e9408104a88: close closable_66e9408104a88: already closed a() start closable_66e9408104a9e: __construct a() end closable_66e9408104a9e: __destruct closable_66e9408104a9e: close closable_66e9408104a9e: closing b() start closable_66e9408104aac: __construct b() catch b() finally closable_66e9408104aac: close closable_66e9408104aac: closing closable_66e9408104aac: __destruct closable_66e9408104aac: close closable_66e9408104aac: already closed a() start closable_66e9408104ac2: __construct a() end closable_66e9408104ac2: __destruct closable_66e9408104ac2: close closable_66e9408104ac2: closing b() start closable_66e9408104ad0: __construct b() return closable_66e9408104ad0: __destruct closable_66e9408104ad0: close closable_66e9408104ad0: closing b() finally a() start closable_66e9408104adf: __construct a() end closable_66e9408104adf: __destruct closable_66e9408104adf: close closable_66e9408104adf: closing b() start closable_66e9408104aed: __construct b() return closable_66e9408104aed: __destruct closable_66e9408104aed: close closable_66e9408104aed: closing b() finally a() start closable_66e9408104afc: __construct a() end closable_66e9408104afc: __destruct closable_66e9408104afc: close closable_66e9408104afc: closing b() start closable_66e9408104b0a: __construct b() catch b() finally closable_66e9408104b0a: close closable_66e9408104b0a: closing closable_66e9408104b0a: __destruct closable_66e9408104b0a: close closable_66e9408104b0a: already closed closable_66e940810499b: __destruct closable_66e940810499b: close closable_66e940810499b: closing
Output for git.master
closable_66e940810116c: __construct closable_66e940810116c: __destruct closable_66e940810116c: close closable_66e940810116c: closing closable_66e940810118d: __construct closable_66e9408101191: __construct closable_66e9408101191: __destruct closable_66e9408101191: close closable_66e9408101191: closing a() start closable_66e94081011a0: __construct a() end closable_66e94081011a0: __destruct closable_66e94081011a0: close closable_66e94081011a0: closing b() start closable_66e94081011af: __construct b() return closable_66e94081011af: __destruct closable_66e94081011af: close closable_66e94081011af: closing b() finally a() start closable_66e94081011c3: __construct a() end closable_66e94081011c3: __destruct closable_66e94081011c3: close closable_66e94081011c3: closing b() start closable_66e94081011d1: __construct b() catch b() finally closable_66e94081011d1: close closable_66e94081011d1: closing closable_66e94081011d1: __destruct closable_66e94081011d1: close closable_66e94081011d1: already closed a() start closable_66e94081011f3: __construct a() end closable_66e94081011f3: __destruct closable_66e94081011f3: close closable_66e94081011f3: closing b() start closable_66e9408101201: __construct b() catch b() finally closable_66e9408101201: close closable_66e9408101201: closing closable_66e9408101201: __destruct closable_66e9408101201: close closable_66e9408101201: already closed a() start closable_66e9408101217: __construct a() end closable_66e9408101217: __destruct closable_66e9408101217: close closable_66e9408101217: closing b() start closable_66e9408101225: __construct b() return closable_66e9408101225: __destruct closable_66e9408101225: close closable_66e9408101225: closing b() finally a() start closable_66e9408101234: __construct a() end closable_66e9408101234: __destruct closable_66e9408101234: close closable_66e9408101234: closing b() start closable_66e9408101241: __construct b() catch b() finally closable_66e9408101241: close closable_66e9408101241: closing closable_66e9408101241: __destruct closable_66e9408101241: close closable_66e9408101241: already closed a() start closable_66e9408101257: __construct a() end closable_66e9408101257: __destruct closable_66e9408101257: close closable_66e9408101257: closing b() start closable_66e9408101265: __construct b() return closable_66e9408101265: __destruct closable_66e9408101265: close closable_66e9408101265: closing b() finally a() start closable_66e9408101274: __construct a() end closable_66e9408101274: __destruct closable_66e9408101274: close closable_66e9408101274: closing b() start closable_66e9408101282: __construct b() return closable_66e9408101282: __destruct closable_66e9408101282: close closable_66e9408101282: closing b() finally a() start closable_66e9408101291: __construct a() end closable_66e9408101291: __destruct closable_66e9408101291: close closable_66e9408101291: closing b() start closable_66e940810129f: __construct b() return closable_66e940810129f: __destruct closable_66e940810129f: close closable_66e940810129f: closing b() finally a() start closable_66e94081012ae: __construct a() end closable_66e94081012ae: __destruct closable_66e94081012ae: close closable_66e94081012ae: closing b() start closable_66e94081012bc: __construct b() catch b() finally closable_66e94081012bc: close closable_66e94081012bc: closing closable_66e94081012bc: __destruct closable_66e94081012bc: close closable_66e94081012bc: already closed a() start closable_66e94081012d2: __construct a() end closable_66e94081012d2: __destruct closable_66e94081012d2: close closable_66e94081012d2: closing b() start closable_66e94081012e0: __construct b() catch b() finally closable_66e94081012e0: close closable_66e94081012e0: closing closable_66e94081012e0: __destruct closable_66e94081012e0: close closable_66e94081012e0: already closed a() start closable_66e94081012f6: __construct a() end closable_66e94081012f6: __destruct closable_66e94081012f6: close closable_66e94081012f6: closing b() start closable_66e9408101304: __construct b() catch b() finally closable_66e9408101304: close closable_66e9408101304: closing closable_66e9408101304: __destruct closable_66e9408101304: close closable_66e9408101304: already closed closable_66e940810118d: __destruct closable_66e940810118d: close closable_66e940810118d: closing
Output for rfc.property-hooks
closable_66e94081044b0: __construct closable_66e94081044b0: __destruct closable_66e94081044b0: close closable_66e94081044b0: closing closable_66e94081044d8: __construct closable_66e94081044db: __construct closable_66e94081044db: __destruct closable_66e94081044db: close closable_66e94081044db: closing a() start closable_66e94081044e8: __construct a() end closable_66e94081044e8: __destruct closable_66e94081044e8: close closable_66e94081044e8: closing b() start closable_66e94081044f3: __construct b() catch b() finally closable_66e94081044f3: close closable_66e94081044f3: closing closable_66e94081044f3: __destruct closable_66e94081044f3: close closable_66e94081044f3: already closed a() start closable_66e9408104519: __construct a() end closable_66e9408104519: __destruct closable_66e9408104519: close closable_66e9408104519: closing b() start closable_66e9408104528: __construct b() return closable_66e9408104528: __destruct closable_66e9408104528: close closable_66e9408104528: closing b() finally a() start closable_66e9408104537: __construct a() end closable_66e9408104537: __destruct closable_66e9408104537: close closable_66e9408104537: closing b() start closable_66e9408104547: __construct b() return closable_66e9408104547: __destruct closable_66e9408104547: close closable_66e9408104547: closing b() finally a() start closable_66e9408104556: __construct a() end closable_66e9408104556: __destruct closable_66e9408104556: close closable_66e9408104556: closing b() start closable_66e940810456e: __construct b() catch b() finally closable_66e940810456e: close closable_66e940810456e: closing closable_66e940810456e: __destruct closable_66e940810456e: close closable_66e940810456e: already closed a() start closable_66e940810458a: __construct a() end closable_66e940810458a: __destruct closable_66e940810458a: close closable_66e940810458a: closing b() start closable_66e940810459c: __construct b() return closable_66e940810459c: __destruct closable_66e940810459c: close closable_66e940810459c: closing b() finally a() start closable_66e94081045aa: __construct a() end closable_66e94081045aa: __destruct closable_66e94081045aa: close closable_66e94081045aa: closing b() start closable_66e94081045b8: __construct b() catch b() finally closable_66e94081045b8: close closable_66e94081045b8: closing closable_66e94081045b8: __destruct closable_66e94081045b8: close closable_66e94081045b8: already closed a() start closable_66e94081045cc: __construct a() end closable_66e94081045cc: __destruct closable_66e94081045cc: close closable_66e94081045cc: closing b() start closable_66e94081045d9: __construct b() catch b() finally closable_66e94081045d9: close closable_66e94081045d9: closing closable_66e94081045d9: __destruct closable_66e94081045d9: close closable_66e94081045d9: already closed a() start closable_66e94081045ed: __construct a() end closable_66e94081045ed: __destruct closable_66e94081045ed: close closable_66e94081045ed: closing b() start closable_66e94081045fa: __construct b() catch b() finally closable_66e94081045fa: close closable_66e94081045fa: closing closable_66e94081045fa: __destruct closable_66e94081045fa: close closable_66e94081045fa: already closed a() start closable_66e940810460e: __construct a() end closable_66e940810460e: __destruct closable_66e940810460e: close closable_66e940810460e: closing b() start closable_66e940810461b: __construct b() catch b() finally closable_66e940810461b: close closable_66e940810461b: closing closable_66e940810461b: __destruct closable_66e940810461b: close closable_66e940810461b: already closed a() start closable_66e940810462f: __construct a() end closable_66e940810462f: __destruct closable_66e940810462f: close closable_66e940810462f: closing b() start closable_66e940810463c: __construct b() return closable_66e940810463c: __destruct closable_66e940810463c: close closable_66e940810463c: closing b() finally a() start closable_66e940810464b: __construct a() end closable_66e940810464b: __destruct closable_66e940810464b: close closable_66e940810464b: closing b() start closable_66e9408104658: __construct b() return closable_66e9408104658: __destruct closable_66e9408104658: close closable_66e9408104658: closing b() finally closable_66e94081044d8: __destruct closable_66e94081044d8: close closable_66e94081044d8: 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:
28.52 ms | 443 KiB | 5 Q