3

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.

  • 2
    Wut? That's the weirdest thing I've ever heard. There's no rational reason to disable traits; it's not like it's a security critical feature. Might as well disable classes and interfaces while you're at it. Sure that rep wasn't talking out of their behind? – deceze Sep 07 '15 at 07:56
  • @deceze They were my thoughts as well hence the question. Rep said they had no idea why and that the response was from the ops team. I was hoping someone else with rackspace cloud site hosting could replicate the issue and perhaps someone else may have a reason why. – Pollywaffle Sep 07 '15 at 09:41
  • 1
    That is nuts. I’ve never heard anything like that before. How do you disable a specific language feature? – Martin Bean Sep 07 '15 at 12:45

2 Answers2

2

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.

0

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

Joako-stackoverflow
  • 506
  • 1
  • 6
  • 16
  • It's more that I am using packages that use traits so it's not really an option to modify the code. Interestingly it will run fine up until you call a method that is implemented via a trait. – Pollywaffle Sep 08 '15 at 06:57