3v4l.org

run code in 200+ PHP versions simultaneously
<?php class Foo { private DateTimeImmutable $bar; private ?string $foo; public function getBar(): DateTimeImmutable { return $this->bar ??= new DateTimeImmutable(); } public function getFoo(): ?string { return $this->foo ??= null; } public function setFoo(string $foo): self { $this->foo = $foo; return $this; } } $foo = new Foo(); var_dump($foo->getBar()); var_dump($foo->getBar()); var_dump($foo->getFoo()); $foo->setFoo('test'); var_dump($foo->getFoo());
based on MDAPb
Output for 7.4.0
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000320" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000320" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } NULL string(4) "test"
Output for 7.4.0rc6
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000435" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000435" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } NULL string(4) "test"
Output for 7.4.0rc5
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000302" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000302" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } NULL string(4) "test"
Output for 7.4.0rc4
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.001289" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.001289" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } NULL string(4) "test"
Output for 7.4.0rc3
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000379" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000379" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } NULL string(4) "test"
Output for 7.4.0rc2
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000305" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000305" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } NULL string(4) "test"
Output for 7.4.0rc1
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000292" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000292" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } NULL string(4) "test"
Output for 7.4.0beta4
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000295" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000295" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } NULL string(4) "test"
Output for 7.4.0beta2
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000365" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000365" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } NULL string(4) "test"
Output for 7.4.0beta1
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000434" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000434" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } NULL string(4) "test"
Output for 7.4.0alpha3
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000419" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000419" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } NULL string(4) "test"
Output for 7.4.0alpha2
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000387" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000387" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } NULL string(4) "test"
Output for 7.4.0alpha1
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000425" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000425" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } NULL string(4) "test"
Output for 7.1.0 - 7.3.12
Parse error: syntax error, unexpected 'DateTimeImmutable' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /in/U02G2 on line 4
Process exited with code 255.
Output for 5.4.0 - 7.0.33
Parse error: syntax error, unexpected 'DateTimeImmutable' (T_STRING), expecting variable (T_VARIABLE) in /in/U02G2 on line 4
Process exited with code 255.
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE in /in/U02G2 on line 4
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING, expecting T_VARIABLE in /in/U02G2 on line 4
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/U02G2 on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/U02G2 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/U02G2 on line 4
Process exited with code 255.