<?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
You have javascript disabled. You will not be able to edit any code.