New features after the php5.0

Source: Internet
Author: User

I. PHP5.3

1. Support namespaces

2. Add goto statement

    Public function teststop ()    {        goto  aaa;         1 ;        AAA:        2;    }

3. Added two magic methods __callstatic () is enabled when a static method is called that does not exist or is private, and the __invoke () method is called automatically when an attempt is made to invoke an object in a way that invokes a function.

   Publicfunction __invoke () {//todo:implement __invoke () method.Echo222; //$a =new tianye (); //echo $a ();    }     Publicfunction __tostring () {//todo:implement __tostring () method. //$a =new tianye (); //echo $a;        return 'SSS'; }     Public  Staticfunction __callstatic ($name, $arr) {DD ($arr); }

4. Add support for Nowdoc syntax

        $c= ' 222 ';         $a=<<< tydskdkskdks,$cty; // This syntax defaults to double quotation-mark parsing variables, so the output is dskdkskdks,222//but if Ty plus single quotation marks        $c= ' 222 ';         $a=<<< ' ty 'dskdkskdks,$cty; // this time the resolution is to parse the single quotation mark, the variable will not be parsed//output is Dskdkskdks, $c,//is actually ty if nothing add = = "Ty", according to double quotation marks to resolve the variable

Two php5.4

1. New Trait

//traits cannot be instantiated by itself, only by the classTrait sayworld{ Public functionSayHello () {Echo' world! '; }}classmyhelloworld{//include the members in the Sayworld     UseSayworld;}$xxoo=NewMyhelloworld ();//the SayHello () function is from the Sayworld component.$xxoo-SayHello ();//method overrides the priority levelclassThe methods in this class of the class have the highest precedence, down trait, and finally the extends method, that is, if there is the same method, the last class method that is executed, trait and the parent are common, the method of trait is executed .

2. New syntax for short arrays

// the original array notation $arr Array ("Key" = "value", "key2" = "value2"); $arr Array (1,2,3,4); // Shorthand Form $arr = ["Key" = "value", "key2" = "value2"]; $arr = [1,2,3,4];

3. For functions, if the returned array can be parsed directly

        $a= ' up ';         Echo Explode (', ',$a) [1];         exit;    

4. Add a member that returns a class when instantiated

(new Foo ()),Bar (); // Generally, if you have a constructor, do not call this

5.session Support for uploading progress

$_SESSION["upload_progress_name"]you can get the current file upload progress information, combined with Ajax can easily implement the upload progress bar.

6. Let JSON understand Chinese

$a=[' naame ' + ' express fee '];        DD (Json_encode ($a)); // {"Naame": "\u5feb\u9012\u8d39"} "        DD (Json_encode ($a, json_unescaped_unicode)); // {"Naame": "Courier Fee"}

7. The default encoding changes from Iso-8859-1 to Utf-8

Three: php5.5

1. New Generators

The yield keyword is used to return values one at a time when the function needs to return an iterator.

  functionNumber10 () { for($i= 1;$i<= 10;$i+ = 1) Yield$i;//equivalent to defining an array of 1-10 and returning    }     Public functionTeststop () {$a=$this-Number10 (); foreach($a  as $v){            Echo $v,Php_eol; }//Output 1-10}

2.foreach Support List

$array = [    [1, 2],    [3, 4],]; foreach ($arrayaslist($a$b)) {    echo$a . $b\ n ";}

New features after the php5.0

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.