3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Thing { private $foo; private $bar; private $qux; public function __construct($foo, $bar, $qux) { $this->foo = $foo; $this->bar = $bar; $this->qux = $qux; } } class Builder { private $foo; private $bar; public function withFoo($foo) { $this->foo = $foo; return $this; } public function withBar($bar) { $this->bar = $bar; return $this; } public function withQux($qux) { try { return new Thing($this->foo, $this->bar, $qux); } finally { $this->reset(); } } private function reset() { $this->foo = null; $this->bar = null; } } function test(Builder $builder) { return [ $builder->withFoo('a')->withBar('b')->withQux('c'), $builder->withFoo('d')->withQux('e'), $builder->withQux('f'), ]; } var_dump(test(new Builder()));
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 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.19, 8.3.0 - 8.3.7
array(3) { [0]=> object(Thing)#2 (3) { ["foo":"Thing":private]=> string(1) "a" ["bar":"Thing":private]=> string(1) "b" ["qux":"Thing":private]=> string(1) "c" } [1]=> object(Thing)#3 (3) { ["foo":"Thing":private]=> string(1) "d" ["bar":"Thing":private]=> NULL ["qux":"Thing":private]=> string(1) "e" } [2]=> object(Thing)#4 (3) { ["foo":"Thing":private]=> NULL ["bar":"Thing":private]=> NULL ["qux":"Thing":private]=> string(1) "f" } }
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected 'finally' (T_STRING), expecting catch (T_CATCH) in /in/tos6Z on line 42
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected T_STRING, expecting T_CATCH in /in/tos6Z on line 42
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING, expecting T_CATCH in /in/tos6Z on line 42
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/tos6Z on line 6
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/tos6Z on line 6
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/tos6Z on line 6
Process exited with code 255.

preferences:
278.92 ms | 402 KiB | 460 Q