3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public $foo; public function __wakeup() { echo 'In foo', PHP_EOL, PHP_EOL; $this->foo = null; } public function __destruct() { echo 'Destruct foo', PHP_EOL, PHP_EOL; } } class Bar { public $bar; public function __wakeup() { echo 'In bar', PHP_EOL, PHP_EOL; $this->bar = null; } public function __destruct() { echo 'Destruct bar', PHP_EOL, PHP_EOL; throw new \Exception('x'); } } $f = new Foo; $b = new Bar; $f->foo = $b; $b->bar = $f; try { var_dump(unserialize(serialize([$f]))); } catch (\Throwable $e) { echo $e, PHP_EOL, PHP_EOL; } echo "==========", PHP_EOL, PHP_EOL; try { var_dump(unserialize(serialize([$f, $b]))); } catch (\Throwable $e) { echo $e, PHP_EOL, PHP_EOL; } echo "==========", PHP_EOL, PHP_EOL; try { var_dump(unserialize(serialize([$b, $f]))); } catch (\Throwable $e) { echo $e, PHP_EOL, PHP_EOL; } echo "==========", PHP_EOL, PHP_EOL;
Output for 7.0.15 - 7.0.33, 7.1.1 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
In bar In foo Destruct bar Exception: x in /in/tnh2R:26 Stack trace: #0 /in/tnh2R(8): Bar->__destruct() #1 [internal function]: Foo->__wakeup() #2 /in/tnh2R(36): unserialize('a:1:{i:0;O:3:"F...') #3 {main} ========== In bar In foo array(2) { [0]=> object(Foo)#3 (1) { ["foo"]=> NULL } [1]=> object(Bar)#4 (1) { ["bar"]=> NULL } } Destruct foo Destruct bar Exception: x in /in/tnh2R:26 Stack trace: #0 /in/tnh2R(43): Bar->__destruct() #1 {main} ========== In foo In bar array(2) { [0]=> object(Bar)#5 (1) { ["bar"]=> NULL } [1]=> object(Foo)#4 (1) { ["foo"]=> NULL } } Destruct bar Destruct foo Exception: x in /in/tnh2R:26 Stack trace: #0 /in/tnh2R(49): Bar->__destruct() #1 {main} ========== Destruct foo Destruct bar Fatal error: Uncaught Exception: x in /in/tnh2R:26 Stack trace: #0 [internal function]: Bar->__destruct() #1 {main} thrown in /in/tnh2R on line 26
Process exited with code 255.
Output for 7.0.0 - 7.0.14, 7.1.0
In bar In foo Destruct bar Destruct foo Exception: x in /in/tnh2R:26 Stack trace: #0 [internal function]: Bar->__destruct() #1 /in/tnh2R(36): unserialize('a:1:{i:0;O:3:"F...') #2 {main} ========== In bar In foo Destruct bar Destruct foo Exception: x in /in/tnh2R:26 Stack trace: #0 [internal function]: Bar->__destruct() #1 /in/tnh2R(43): unserialize('a:2:{i:0;O:3:"F...') #2 {main} ========== In foo In bar Destruct foo array(2) { [0]=> object(Bar)#5 (1) { ["bar"]=> NULL } [1]=> NULL } Destruct bar Exception: x in /in/tnh2R:26 Stack trace: #0 /in/tnh2R(49): Bar->__destruct() #1 {main} ========== Destruct foo Destruct bar Fatal error: Uncaught Exception: x in /in/tnh2R:26 Stack trace: #0 [internal function]: Bar->__destruct() #1 {main} thrown in /in/tnh2R on line 26
Process exited with code 255.
Output for 5.6.30 - 5.6.40
In bar In foo Destruct bar Fatal error: Uncaught exception 'Exception' with message 'x' in /in/tnh2R:26 Stack trace: #0 /in/tnh2R(8): Bar->__destruct() #1 [internal function]: Foo->__wakeup() #2 /in/tnh2R(36): unserialize('a:1:{i:0;O:3:"F...') #3 {main} thrown in /in/tnh2R on line 26
Process exited with code 255.
Output for 5.4.39 - 5.4.45, 5.5.23 - 5.5.38, 5.6.7 - 5.6.29
In bar In foo Destruct bar Destruct foo Fatal error: Uncaught exception 'Exception' with message 'x' in /in/tnh2R:26 Stack trace: #0 [internal function]: Bar->__destruct() #1 /in/tnh2R(36): unserialize('a:1:{i:0;O:3:"F...') #2 {main} thrown in /in/tnh2R on line 26
Process exited with code 255.
Output for 5.4.0 - 5.4.38, 5.5.0 - 5.5.22, 5.6.0 - 5.6.6
In bar In foo Destruct bar Destruct foo Fatal error: Uncaught exception 'Exception' with message 'x' in /in/tnh2R:26 Stack trace: #0 /in/tnh2R(8): Bar->__destruct() #1 [internal function]: Foo->__wakeup() #2 /in/tnh2R(36): unserialize('a:1:{i:0;O:3:"F...') #3 {main} thrown in /in/tnh2R on line 26
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[', expecting ')' in /in/tnh2R on line 36
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/tnh2R on line 26 Parse error: syntax error, unexpected '[', expecting ')' in /in/tnh2R on line 36
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/tnh2R on line 26 Parse error: parse error, unexpected '[', expecting ')' in /in/tnh2R on line 36
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/tnh2R on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/tnh2R on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/tnh2R on line 4
Process exited with code 255.

preferences:
322.82 ms | 401 KiB | 468 Q