Skip to main content
PHP Code Reorder Hard +35 XP

Trait Usage

Arrange trait declaration and usage correctly.

Click lines in the correct order

Available lines4 left

Your order

Click lines above to build your solution.

Show answer and explanation

Answer: trait Greetable { public function greet() { return "Hello!"; } } class User { use Greetable; } $u = new User(); echo $u->greet();

Declare the trait before the class that uses it. Then instantiate and call the mixed-in method.

Hint: Trait must be declared before the class that uses it.

What this challenge tests

Code Reorder in PHP: traits, oop.

Related challenges