質問

I have a project written in CakePHP2.3 and I'm thinking about upgrading PHP to version 5.4. I'm trying to keep the code DRY and the traits from PHP5.4 could help with that. My current PHP version is 5.3.3.

Before I start installing stuff on the server, I want to know if this is a good idea.

  • Have you used CakePHP2.3 & PHP5.4 together and, if yes, have you encountered any compability issues?

  • Have you used the new traits feature from PHP5.4 and, if yes, did you have any problems with it?

役に立ちましたか?

解決

I have a CakePHP 2.2 project on a PHP 5.4 server. It works fine as CakePHP's classes are properly written with inheritance patterns. However, if your application implements inheritance improperly, then you will get PHP errors in 5.4 that you did not get in 5.3.

class parentClass{
    public function test($foo);
}

class childClass extends parentClass{
    //Does not properly implement test
    public function test();
}

Otherwise, CakePHP 2.0+ is completely compatible. (Since CakePHP 2.3 is still in development, I have not upgraded. But it is API compatible with 2.2, so the answer applies to all versions of the 2.0 branch).

Traits are not officially supported in CakePHP until version 3.0. However, I have used them without issue in my project. In fact, they come in very handy! You cannot use any CakePHP method for importing them (not supported yet), but just use standard require_once('trait_file_name.php'); and then apply the trait to your class / interface.

CakePHP 3.0 will require PHP 5.4, so the development patterns you look to use are on their way in.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top