Php5.3 considerations

Source: Internet
Author: User
Tags constant definition
This article provides a detailed analysis of some things that need to be paid attention to in php5.3. For more information, see php5.3.
New features
1. namespace is supported)
Before 5.3
The code is as follows:
Class Zend_Db_Table_Select {
// Indicates that the current class file is located under Zend/Db/Table
}

5.3
The code is as follows:
Namespace Zend/Db/Table
Class Select {
}

2. support for delayed static binding
Before 5.3 (_ CLASS _ obtains the CLASS name) self: who ()
The code is as follows:
Class {
Public static function who (){
Echo _ CLASS __;
}
Public static function test (){
Self: who ();
}
}
Class B extends {
Public static function who (){
Echo _ CLASS __;
}
}
B: test ();
?>

Output
5.3 (_ CLASS _ get CLASS name) static: who ();
The code is as follows:
Class {
Public static function who (){
Echo _ CLASS __;
}
Public static function test (){
Static: who (); // latency static binding is implemented here
}
}
Class B extends {
Public static function who (){
Echo _ CLASS __;
}
}
B: test ();
?>

Output B

3. support for goto statements
Most computer programming languages support unconditional redirection to the goto statement. when the program is executed to the goto statement, the program is switched to the position indicated by the label in the goto statement to continue execution.

4. support for closures
The code is as follows:
$ Msg = "hello ";
$ Callback = function () use ($ msg ){
Print_r ($ msg );
}
$ Msg = "hello world! ";
Callback ($ callback );

Output
Hello
Hello world!

5. added the magic method _ callStatic ()
PHP originally had a magic method _ call (). when the code calls a non-existent method of the object, the magic method is automatically called.
The new _ callStatic () method is only used for static class methods. When you try to call a static method that does not exist in the class, the __callstatic () magic method is automatically called.

6. added a constant definition method (sometimes code errors, such as undefined HE, you need to check whether const is supported)
The code is as follows:
Const CONSTANT = 'Hello World ';

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.