public function printX() { var_dump(self::$x); self::$x = 4; }
<?php trait MY_TRAIT { public function sayHello() { echo 'World!'; } } class MY_CLASS { use MY_TRAIT; } $MY_OBJ = new MY_CLASS(); $MY_OBJ->sayHello(); ?>
<?php trait MY_TRAIT { public function sayHello() { echo "Hello World!\n"; } } class MY_CLASS { use MY_TRAIT { sayHello as falaOi; } } $a = new MY_CLASS(); $a->falaOi();
<?php trait MY_TRAIT1 { public function sayHello() { echo "Hello from MY_TRAIT1\n"; } } trait MY_TRAIT2 { use MY_TRAIT1; public function sayHello() { echo "Hello from MY_TRAIT2\n"; } } class MY_CLASS { use MY_TRAIT2; } $o = new MY_CLASS(); $o->sayHello();
<?php trait MY_TRAIT { public static $x = 3; } class MY_CLASS { use MY_TRAIT; public function printX() { var_dump(self::$x); } } $o = new MY_CLASS(); $o->printX();
<?php trait T1 { var $x = 1977; } trait T2 { var $x = 1977; } class MY_CLASS { use T1, T2; var $abc = 1; public function printProps() { var_dump($this->x); } } $o = new MY_CLASS(); $o->printProps();