简体   繁体   English

可以在5.4.x中禁用PHP Traits吗?

[英]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. 我有一个客户使用Rackspace Cloud Sites在他们的平台上宣传PHP 5.4但我通过他们的在线支持告知我不能使用特征。

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". 当使用特征时,我收到500错误,并且发现代码没有问题,我要求他们的在线支持被告知“在我们的环境中不允许这样做”。 Using the basic PHP example code below results in a 500 Internal Server Error: 使用下面的基本PHP示例代码会导致500内部服务器错误:

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? 是否有某些原因导致Traits被禁用或甚至可能被禁用? The version reported by phpinfo() is 5.4.10. phpinfo()报告的版本是5.4.10。

After some discussions with rackspace support it seems the issue is with xcache and execution of some items such as traits. 在与rackspace支持进行一些讨论之后,问题似乎是xcache和一些项目(如traits)的执行。 Adding the following line to .htaccess resolves the issue: 将以下行添加到.htaccess可解决此问题:

php_flag xcache.cacher 0

Seems it is not a rackspace issue but an xcache issue. 似乎它不是机架空间问题,而是xcache问题。

Php traits cannot be disabled. 不能禁用Php特征。 If you have a limited use of traits, you could comment out the "use" statements. 如果您对特征的使用有限,则可以注释掉“使用”语句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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