Search code examples
phptraitsrackspace

Can PHP Traits be disabled in 5.4.x?


I have a client using Rackspace Cloud Sites which advertise PHP 5.4 on their platform but I have been advised via their online support that traits cannot be used.

When using traits I receive a 500 error and finding no issue with the code I asked their online support to be told "it is not allowed in our environment". Using the basic PHP example code below results in a 500 Internal Server Error:

class Base {
    public function sayHello() {
        echo 'Hello ';
    }
}

trait SayWorld {
    public function sayHello() {
        parent::sayHello();
        echo 'World!';
    }
}

class MyHelloWorld extends Base {
    use SayWorld;
}

$o = new MyHelloWorld();
$o->sayHello();

Is there some reason why Traits would be disabled or can they even be disabled? The version reported by phpinfo() is 5.4.10.


Solution

  • After some discussions with rackspace support it seems the issue is with xcache and execution of some items such as traits. Adding the following line to .htaccess resolves the issue:

    php_flag xcache.cacher 0
    

    Seems it is not a rackspace issue but an xcache issue.