I have nothing to do today. I occasionally saw a brief description of the differences between each version in the version selection section of phpstorm, so I summarized it.
Compared with the previous version, the biggest difference between PHP5.3 and PHP5.3 is the namespace and anonymous functions, which are commonly used in daily development and major frameworks, so I won’t go into details.
The main update of PHP5.4 is the array abbreviation syntax format and traits.
Regarding the array abbreviation, it is quite simple to say. It just adds a new declaration method for the array, as follows:
<code>// PHP5.4之前 $array = array( "foo" => "bar", "bar" => "foo", ); // 自 PHP 5.4 起 $array = [ "foo" => "bar", "bar" => "foo", ];</code>
As for the traits of PHP5.4, it is relatively rare. The code description:
<code>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();</code>
Explanation: The result is: 'Hello World!', methods inherited from the base class will be overridden by methods with the same name in the trait. Methods in the current class overwrite members with the same name in the trait; if attributes are defined in the trait, attributes with the same name cannot be defined in the current class; trait Abstract methods and static members can also be defined. Multiple traits can be used, separated by commas, as follows:
<code>use SayHello1,SayHello2; </code>
If there are members with the same name in SayHello1 and SayHello2, a fatal error will occur. The solution is as follows:
<code>use SayHello1,SayHello2 { SayHello1::sayHello insteadof SayHello2; // 意思是用SayHello1中的sayHello方法代替SayHello2中的同名方法,注:此处的sayHello不一定是静态方法 // ... // 或 SayHello1::sayHello as sayHello1; // 为其另取一个名字,也可解决 } </code>
The changes in PHP5.5 are mainly in exception handling Add finally keyword and generator generator.
Regarding finally, code description:
<code>try { throw new ErrorException('Some Error Message'); } catch (ErrorException $e) { echo $e->getMessage()."111 \n"; } catch(Exception $e) { echo $e->getMessage()."222 \n"; } finally { echo 'finally'; }</code>
Regardless of whether an exception occurs or not, finally will be output.
Regarding the generator, I read the manual, but I don’t know what it is. Got it, plus...
Let’s get here first today...
The above has introduced a brief summary of the important updates of PHP53, 54, 55, and 56 versions (Part 1), including relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.