user1203914
user1203914

Reputation:

Why are traits not working?

I am trying to learn traits. I have used the example from PHP manual, but it does not work - why?

trait ezcReflectionReturnInfo {
    function getReturnType() { /*1*/ }
    function getReturnDescription() { /*2*/ }
}

class ezcReflectionMethod extends ReflectionMethod {
    use ezcReflectionReturnInfo;

}

class ezcReflectionFunction extends ReflectionFunction {
    use ezcReflectionReturnInfo;

}

I get the error:

Parse error: syntax error, unexpected T_STRING in /path/index.php on line 23 

Upvotes: 1

Views: 2879

Answers (1)

ThinkingMonkey
ThinkingMonkey

Reputation: 12727

Check your PHP version.

do echo PHP_VERSION_ID;

From Traits:PHP Manual

Traits

As of PHP 5.4.0, PHP implements a method of code reuse called Traits.

Upvotes: 5

Related Questions