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

preferences:
31.75 ms | 404 KiB | 5 Q