简体   繁体   中英

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.

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.

Php traits cannot be disabled. If you have a limited use of traits, you could comment out the "use" statements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM