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(...$params): Closable { return new self(...$params); } } 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
first66e940d0095f9: __construct first66e940d0095f9: __destruct first66e940d0095f9: close first66e940d0095f9: closing $foo66e940d009638: __construct third66e940d009641: __construct third66e940d009641: __destruct third66e940d009641: close third66e940d009641: closing a() start $a66e940d00965f: __construct a() end $a66e940d00965f: __destruct $a66e940d00965f: close $a66e940d00965f: closing b() start $b66e940d009680: __construct b() return $b66e940d009680: __destruct $b66e940d009680: close $b66e940d009680: closing b() finally a() start $a66e940d0096ac: __construct a() end $a66e940d0096ac: __destruct $a66e940d0096ac: close $a66e940d0096ac: closing b() start $b66e940d0096ce: __construct b() return $b66e940d0096ce: __destruct $b66e940d0096ce: close $b66e940d0096ce: closing b() finally a() start $a66e940d0096f1: __construct a() end $a66e940d0096f1: __destruct $a66e940d0096f1: close $a66e940d0096f1: closing b() start $b66e940d009711: __construct b() catch b() finally $b66e940d009711: close $b66e940d009711: closing $b66e940d009711: __destruct $b66e940d009711: close $b66e940d009711: already closed a() start $a66e940d009758: __construct a() end $a66e940d009758: __destruct $a66e940d009758: close $a66e940d009758: closing b() start $b66e940d009778: __construct b() catch b() finally $b66e940d009778: close $b66e940d009778: closing $b66e940d009778: __destruct $b66e940d009778: close $b66e940d009778: already closed a() start $a66e940d0097a8: __construct a() end $a66e940d0097a8: __destruct $a66e940d0097a8: close $a66e940d0097a8: closing b() start $b66e940d0097c8: __construct b() catch b() finally $b66e940d0097c8: close $b66e940d0097c8: closing $b66e940d0097c8: __destruct $b66e940d0097c8: close $b66e940d0097c8: already closed a() start $a66e940d0097f9: __construct a() end $a66e940d0097f9: __destruct $a66e940d0097f9: close $a66e940d0097f9: closing b() start $b66e940d009818: __construct b() catch b() finally $b66e940d009818: close $b66e940d009818: closing $b66e940d009818: __destruct $b66e940d009818: close $b66e940d009818: already closed a() start $a66e940d009883: __construct a() end $a66e940d009883: __destruct $a66e940d009883: close $a66e940d009883: closing b() start $b66e940d0098ab: __construct b() catch b() finally $b66e940d0098ab: close $b66e940d0098ab: closing $b66e940d0098ab: __destruct $b66e940d0098ab: close $b66e940d0098ab: already closed a() start $a66e940d0098ec: __construct a() end $a66e940d0098ec: __destruct $a66e940d0098ec: close $a66e940d0098ec: closing b() start $b66e940d009916: __construct b() return $b66e940d009916: __destruct $b66e940d009916: close $b66e940d009916: closing b() finally a() start $a66e940d00993e: __construct a() end $a66e940d00993e: __destruct $a66e940d00993e: close $a66e940d00993e: closing b() start $b66e940d009963: __construct b() catch b() finally $b66e940d009963: close $b66e940d009963: closing $b66e940d009963: __destruct $b66e940d009963: close $b66e940d009963: already closed a() start $a66e940d0099a3: __construct a() end $a66e940d0099a3: __destruct $a66e940d0099a3: close $a66e940d0099a3: closing b() start $b66e940d0099c4: __construct b() return $b66e940d0099c4: __destruct $b66e940d0099c4: close $b66e940d0099c4: closing b() finally a() start $a66e940d0099f5: __construct a() end $a66e940d0099f5: __destruct $a66e940d0099f5: close $a66e940d0099f5: closing b() start $b66e940d009a16: __construct b() return $b66e940d009a16: __destruct $b66e940d009a16: close $b66e940d009a16: closing b() finally $foo66e940d009638: __destruct $foo66e940d009638: close $foo66e940d009638: closing
Output for git.master
first66e940d0027e8: __construct first66e940d0027e8: __destruct first66e940d0027e8: close first66e940d0027e8: closing $foo66e940d00281a: __construct third66e940d002821: __construct third66e940d002821: __destruct third66e940d002821: close third66e940d002821: closing a() start $a66e940d00283d: __construct a() end $a66e940d00283d: __destruct $a66e940d00283d: close $a66e940d00283d: closing b() start $b66e940d002855: __construct b() catch b() finally $b66e940d002855: close $b66e940d002855: closing $b66e940d002855: __destruct $b66e940d002855: close $b66e940d002855: already closed a() start $a66e940d002898: __construct a() end $a66e940d002898: __destruct $a66e940d002898: close $a66e940d002898: closing b() start $b66e940d0028b2: __construct b() catch b() finally $b66e940d0028b2: close $b66e940d0028b2: closing $b66e940d0028b2: __destruct $b66e940d0028b2: close $b66e940d0028b2: already closed a() start $a66e940d0028db: __construct a() end $a66e940d0028db: __destruct $a66e940d0028db: close $a66e940d0028db: closing b() start $b66e940d0028f4: __construct b() return $b66e940d0028f4: __destruct $b66e940d0028f4: close $b66e940d0028f4: closing b() finally a() start $a66e940d00290f: __construct a() end $a66e940d00290f: __destruct $a66e940d00290f: close $a66e940d00290f: closing b() start $b66e940d002928: __construct b() return $b66e940d002928: __destruct $b66e940d002928: close $b66e940d002928: closing b() finally a() start $a66e940d002944: __construct a() end $a66e940d002944: __destruct $a66e940d002944: close $a66e940d002944: closing b() start $b66e940d00295e: __construct b() return $b66e940d00295e: __destruct $b66e940d00295e: close $b66e940d00295e: closing b() finally a() start $a66e940d002978: __construct a() end $a66e940d002978: __destruct $a66e940d002978: close $a66e940d002978: closing b() start $b66e940d002990: __construct b() catch b() finally $b66e940d002990: close $b66e940d002990: closing $b66e940d002990: __destruct $b66e940d002990: close $b66e940d002990: already closed a() start $a66e940d0029b7: __construct a() end $a66e940d0029b7: __destruct $a66e940d0029b7: close $a66e940d0029b7: closing b() start $b66e940d0029d0: __construct b() return $b66e940d0029d0: __destruct $b66e940d0029d0: close $b66e940d0029d0: closing b() finally a() start $a66e940d0029ea: __construct a() end $a66e940d0029ea: __destruct $a66e940d0029ea: close $a66e940d0029ea: closing b() start $b66e940d002a03: __construct b() catch b() finally $b66e940d002a03: close $b66e940d002a03: closing $b66e940d002a03: __destruct $b66e940d002a03: close $b66e940d002a03: already closed a() start $a66e940d002a2c: __construct a() end $a66e940d002a2c: __destruct $a66e940d002a2c: close $a66e940d002a2c: closing b() start $b66e940d002a46: __construct b() return $b66e940d002a46: __destruct $b66e940d002a46: close $b66e940d002a46: closing b() finally a() start $a66e940d002a60: __construct a() end $a66e940d002a60: __destruct $a66e940d002a60: close $a66e940d002a60: closing b() start $b66e940d002a79: __construct b() catch b() finally $b66e940d002a79: close $b66e940d002a79: closing $b66e940d002a79: __destruct $b66e940d002a79: close $b66e940d002a79: already closed a() start $a66e940d002aa0: __construct a() end $a66e940d002aa0: __destruct $a66e940d002aa0: close $a66e940d002aa0: closing b() start $b66e940d002ab8: __construct b() return $b66e940d002ab8: __destruct $b66e940d002ab8: close $b66e940d002ab8: closing b() finally $foo66e940d00281a: __destruct $foo66e940d00281a: close $foo66e940d00281a: closing
Output for rfc.property-hooks
first66e940d007669: __construct first66e940d007669: __destruct first66e940d007669: close first66e940d007669: closing $foo66e940d0076a8: __construct third66e940d0076af: __construct third66e940d0076af: __destruct third66e940d0076af: close third66e940d0076af: closing a() start $a66e940d0076c7: __construct a() end $a66e940d0076c7: __destruct $a66e940d0076c7: close $a66e940d0076c7: closing b() start $b66e940d0076de: __construct b() catch b() finally $b66e940d0076de: close $b66e940d0076de: closing $b66e940d0076de: __destruct $b66e940d0076de: close $b66e940d0076de: already closed a() start $a66e940d00771b: __construct a() end $a66e940d00771b: __destruct $a66e940d00771b: close $a66e940d00771b: closing b() start $b66e940d00773f: __construct b() return $b66e940d00773f: __destruct $b66e940d00773f: close $b66e940d00773f: closing b() finally a() start $a66e940d007761: __construct a() end $a66e940d007761: __destruct $a66e940d007761: close $a66e940d007761: closing b() start $b66e940d007786: __construct b() return $b66e940d007786: __destruct $b66e940d007786: close $b66e940d007786: closing b() finally a() start $a66e940d0077aa: __construct a() end $a66e940d0077aa: __destruct $a66e940d0077aa: close $a66e940d0077aa: closing b() start $b66e940d0077ce: __construct b() catch b() finally $b66e940d0077ce: close $b66e940d0077ce: closing $b66e940d0077ce: __destruct $b66e940d0077ce: close $b66e940d0077ce: already closed a() start $a66e940d0077fe: __construct a() end $a66e940d0077fe: __destruct $a66e940d0077fe: close $a66e940d0077fe: closing b() start $b66e940d007821: __construct b() return $b66e940d007821: __destruct $b66e940d007821: close $b66e940d007821: closing b() finally a() start $a66e940d007847: __construct a() end $a66e940d007847: __destruct $a66e940d007847: close $a66e940d007847: closing b() start $b66e940d007863: __construct b() return $b66e940d007863: __destruct $b66e940d007863: close $b66e940d007863: closing b() finally a() start $a66e940d0078a6: __construct a() end $a66e940d0078a6: __destruct $a66e940d0078a6: close $a66e940d0078a6: closing b() start $b66e940d0078c4: __construct b() catch b() finally $b66e940d0078c4: close $b66e940d0078c4: closing $b66e940d0078c4: __destruct $b66e940d0078c4: close $b66e940d0078c4: already closed a() start $a66e940d0078f6: __construct a() end $a66e940d0078f6: __destruct $a66e940d0078f6: close $a66e940d0078f6: closing b() start $b66e940d007918: __construct b() return $b66e940d007918: __destruct $b66e940d007918: close $b66e940d007918: closing b() finally a() start $a66e940d007935: __construct a() end $a66e940d007935: __destruct $a66e940d007935: close $a66e940d007935: closing b() start $b66e940d007959: __construct b() return $b66e940d007959: __destruct $b66e940d007959: close $b66e940d007959: closing b() finally a() start $a66e940d00797d: __construct a() end $a66e940d00797d: __destruct $a66e940d00797d: close $a66e940d00797d: closing b() start $b66e940d007997: __construct b() return $b66e940d007997: __destruct $b66e940d007997: close $b66e940d007997: closing b() finally a() start $a66e940d0079be: __construct a() end $a66e940d0079be: __destruct $a66e940d0079be: close $a66e940d0079be: closing b() start $b66e940d0079e0: __construct b() return $b66e940d0079e0: __destruct $b66e940d0079e0: close $b66e940d0079e0: closing b() finally $foo66e940d0076a8: __destruct $foo66e940d0076a8: close $foo66e940d0076a8: 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:
40.15 ms | 427 KiB | 5 Q