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

Shows result from various feature-branches currently under review from the php developers. Contact me to have additional branches featured.

Output for branch php-master
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000402" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000402" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } NULL string(4) "test"
Output for branch php-master+opcache
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000515" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000515" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } NULL string(4) "test"
Output for branch php-master+jit
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000326" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-03 09:39:38.000326" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } NULL string(4) "test"
Output for Typed properties v2
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 Arrow functions
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 Object typehint
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 Array change keys
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 Lexical anon
Parse error: syntax error, unexpected 'DateTimeImmutable' (T_STRING), expecting variable (T_VARIABLE) in /in/U02G2 on line 4
Process exited with code 255.

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