3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait one { public function setOne($data) { $this->{__TRAIT__ . '\data'} = $data; } public function getOne() { return $this->{__TRAIT__ . '\data'}; } } trait two { public function setTwo($data) { $this->{__TRAIT__ . '\data'} = $data; } public function getTwo() { return $this->{__TRAIT__ . '\data'}; } } class Bar { use one; use two; } $bar = new Bar; $bar->setOne(1); $bar->setTwo(2); print_r($bar); echo "Bar getOne: " . $bar->getOne() . '<br>' . PHP_EOL; // echoes 2 instead of wanted 1 echo "Bar getTwo: " . $bar->getTwo() . '<br>' . PHP_EOL; // overwrites $this->data = 1 with 2
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Creation of dynamic property Bar::$one\data is deprecated in /in/oHcn9 on line 7 Deprecated: Creation of dynamic property Bar::$two\data is deprecated in /in/oHcn9 on line 20 Bar Object ( [one\data] => 1 [two\data] => 2 ) Bar getOne: 1<br> Bar getTwo: 2<br>

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:
42.81 ms | 406 KiB | 5 Q