3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Hi { protected $message = 'Hello'; public function setMessage(string $message) { $this->message = $message; } public function sayHello() : Hi { var_dump($this->message); return $this; } } class WrapperCat extends Hi { private $realThing; public function __construct(Hi $realThing) // should be a named constructor instead { $this->realThing = $realThing; } public function sayHello() : Hi { var_dump('WrapperCat Meow! '); return $this->realThing->sayHello(); } } class CopyCat extends Hi { public function __construct(Hi $realThing) // should be a named constructor instead { $this->message = & $realThing->message; } public function sayHello() : Hi { var_dump('CopyCat Meow! ' . $this->message); return $this; } } $hi = new Hi; $wrapperCat = new WrapperCat($hi); $copyCat = new CopyCat($hi); $hi->setMessage('Hello'); var_dump(Hi::class); $hi->sayHello()->sayHello(); var_dump(WrapperCat::class); $wrapperCat->sayHello()->sayHello(); var_dump(CopyCat::class); $copyCat->sayHello()->sayHello(); $hi->setMessage('Hi'); var_dump(Hi::class); $hi->sayHello()->sayHello(); var_dump(WrapperCat::class); $wrapperCat->sayHello()->sayHello(); var_dump(CopyCat::class); $copyCat->sayHello()->sayHello();
Output for rfc.property-hooks, git.master, git.master_jit
string(2) "Hi" string(5) "Hello" string(5) "Hello" string(10) "WrapperCat" string(17) "WrapperCat Meow! " string(5) "Hello" string(5) "Hello" string(7) "CopyCat" string(19) "CopyCat Meow! Hello" string(19) "CopyCat Meow! Hello" string(2) "Hi" string(2) "Hi" string(2) "Hi" string(10) "WrapperCat" string(17) "WrapperCat Meow! " string(2) "Hi" string(2) "Hi" string(7) "CopyCat" string(16) "CopyCat Meow! Hi" string(16) "CopyCat Meow! Hi"

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:
75.26 ms | 2202 KiB | 4 Q