3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private DateTimeImmutable $bar; private ?string $foo; public function getBar(): DateTimeImmutable { return $this->bar ??= new DateTimeImmutable(); } public static function getFoo(): ?string { return $this->foo ??= null; } public static 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());
Output for git.master
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-02 18:30:30.003874" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-02 18:30:30.003874" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } Fatal error: Uncaught Error: Using $this when not in object context in /in/MDAPb:14 Stack trace: #0 /in/MDAPb(29): Foo::getFoo() #1 {main} thrown in /in/MDAPb on line 14
Process exited with code 255.
Output for git.master_jit
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-02 18:30:30.003909" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-02 18:30:30.003909" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } Fatal error: Uncaught Error: Using $this when not in object context in /in/MDAPb:14 Stack trace: #0 /in/MDAPb(29): Foo::getFoo() #1 {main} thrown in /in/MDAPb on line 14
Process exited with code 255.
Output for rfc.property-hooks
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-02 18:30:30.003823" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2019-12-02 18:30:30.003823" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } Fatal error: Uncaught Error: Using $this when not in object context in /in/MDAPb:14 Stack trace: #0 /in/MDAPb(29): Foo::getFoo() #1 {main} thrown in /in/MDAPb on line 14
Process exited with code 255.

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:
61.69 ms | 401 KiB | 8 Q