Important Updates of PHP53, 54, 55, and 56 versions (I)

Source: Internet
Author: User
Tags traits
: This article mainly introduces important updates of PHP53, 54, 55, and 56 versions (I). If you are interested in PHP tutorials, refer to them. Today, I have nothing to do with it. I occasionally see a brief description of the differences between different versions in the version selection field in phpstorm. so I would like to summarize it.


Compared with the previous version, PHP5.3 has the biggest difference: namespace and anonymous functions, which are usually used in many development and major frameworks.
PHP5.4 is mainly updated by the abbreviated array syntax format and traits.
The array abbreviation is also quite simple, but a new declaration method is added for the array, as shown below:

// $ Array = array ("foo" => "bar", "bar" => "foo",) before PHP5.4 ",); // starting from PHP 5.4 $ array = ["foo" => "bar", "bar" => "foo",];

The traits of PHP5.4 is rare. code description:

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();

Note: The result is 'Hello World! ', Methods inherited from the base class will be overwritten by methods with the same name in trait, and the methods in the current class will overwrite members with the same name in trait. if the trait defines attributes, the attributes of the same name cannot be defined in the current class. abstract methods and static members can also be defined in trait. You can use multiple trait, which are separated by commas, as shown below:

use SayHello1,SayHello2;

If SayHello1 and SayHello2 have members of the same name, a fatal error occurs. the solution is as follows:

Use SayHello1, SayHello2 {SayHello1: sayHello insteadof SayHello2; // replace the same name method in SayHello1 with the sayHello method. note: the sayHello here is not necessarily a static method //... // or SayHello1: sayHello as sayHello1; // you can specify another name for it}

In PHP5.5, the finally keyword and generator are added to exception handling.
Code description for finally:

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';}

Finally is output no matter whether exceptions occur.
I have read the manual about the generator. I understand...
Come here today ......

The above describes important updates of PHP53, 54, 55, and 56 versions (I), including some content. I hope to help some friends who are interested in PHP tutorials.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.