PHP5.3 language feature _ PHP Tutorial

Source: Internet
Author: User
PHP5.3 language features. Performance improvement php5.3 overall performance improvement 5-15% md5 () faster 10-15% BetterstackimplementationintheengineConstants move to read-only memory exception processing Process Improvement (simplified, performance improvement

The overall performance of php 5.3 has been improved by 5-15%.

Md5 () faster than 10-15%
Better stack implementation in the engine
Moving Constants to read-only memory
Exception handling Process Improvement (simplified with fewer opcodes)
(Require/include) _ once improvement, remove repeated open
Smaller binary size & startup size with gcc4

New language features

_ DIR __

Before 5.3, in order to obtain the Directory of the current script, the compile function call is required.

CODE:
Echo dirname (_ FILE _); // <PHP 5.3

In 5.3, only one magic constant _ DIR _ is required.

CODE:
Echo _ DIR __; //> = PHP 5.3

? : Operator

Convenient? : Operator. you can quickly obtain non-null values from two values/expressions.

CODE:
$ A = true? : False; // true
$ A = false? : True; // true
$ A = ""? : 1; // 1
$ A = 0? : 2; // 2
$ A = array ()? : Array (1); // array (1 );
$ A = strlen ("")? : Strlen ("a"); // 1

_ CallStatic ()

The magic method _ callStatic is added, which is similar to the function of _ call, but only valid for the static method.

CODE:
Class helper {
Static function _ callStatic ($ name, $ args ){
Echo $ name. '('. implode (',', $ args ).')';
}
}
Helper: test ("foo", "bar"); // test (foo, bar)

Dynamic Call of static method

Dynamic Call of static methods? Dynamic and static combination.

CODE:
Class helper {
Static function foo () {echo _ METHOD __;}
}
$ A = "helper ";
$ B = "foo ";
$ A: $ B (); // helper: foo

Late Static Binding

If you do not know how to translate, it is easier to leave an original article. The timing of Event Processing for static methods has changed. Previously, events were handled during compilation and now events are processed during execution.

Before php 5.3, the following code will output A, but this is not what we need. the whoami method has been redefined in class B. It should have output B to conform to our thinking.

CODE:
Class {
Public static function whoami (){
Echo _ CLASS __;
}
Public static function identity (){
Self: whoami ();
}
}
Class B extends {
Public static function whoami (){
Echo _ CLASS __;
}
}
B: identity (); // A <-- PHP <5.3

The following code uses static: whoami () to call static methods. After php 5.3, because _ CLASS _ is processed during the execution period, class B can be successfully captured in this example.

CODE:
Class {
Public static function whoami (){
Echo _ CLASS __;
}
Public static function identity (){
Static: whoami ();
}
}
Class B extends {
Public static function whoami (){
Echo _ CLASS __;
}
}
B: identity (); // B <--> = PHP 5.3

Mysqlnd

Mysqlnd becomes the default mysql driver in php 5.3. it has the following advantages:

Mysqlnd is easier to compile: because it is an integral part of the php source code tree
The internal mechanism of mysqlnd and php is more closely integrated, and is the optimized mysql driver.
Mysqlnd saves more memory. from the test results, it saves 40% of memory than the traditional mysql expansion.
Mysqlnd is faster
Mysqlnd provides a wide range of performance statistics functions
Mysqlnd uses PHP license to avoid unnecessary copyright disputes

This change should take effect for mysql and pdo_mysql extensions at the same time.

What is mysqlnd?

Mysqlnd is the original php driver of mysql.

However, PDO_MySQL does not support mysqlnd yet. Currently, only mysql (I) extension is supported.

The overall performance of ipvphp 5.3 is improved by 5-15% md5 () faster than 10-15% Better stack implementation in the engine Constants move to read-only memory for exception handling process improvement (simplified ,...

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.