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() : string { return $this->message; } } class CopyCat extends Hi { public function __construct(Hi $realThing) // should be a named constructor instead { $this->message = & $realThing->message; } public function sayHello() : string { return 'Meow! ' . $this->message; } } $hi = new Hi; $hi->setMessage('Hello'); $copyCat = new CopyCat($hi); var_dump($hi->sayHello()); var_dump($copyCat->sayHello()); $hi->setMessage('Hi'); var_dump($hi->sayHello()); var_dump($copyCat->sayHello());
Output for git.master, git.master_jit, rfc.property-hooks
string(5) "Hello" string(11) "Meow! Hello" string(2) "Hi" string(8) "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:
47.01 ms | 1824 KiB | 4 Q