PHP5.3 language Features

Source: Internet
Author: User
Tags strlen

Performance improvement

The overall performance of PHP 5.3 has improved 5-15%

MD5 () Fast 10-15%
Better stack implementation in the engine
Constants moved into Read-only memory.
Exception Process Improvement (simplified, opcodes less)
(require/include) _once improvement, remove duplicate open
Smaller binary size & startup size with GCC4

New language Features

__dir__

Prior to 5.3, a function call was required to get the directory of the current script

CODE:
echo dirname (__file__); < PHP 5.3

In 5.3, only need a magic constant __dir__ to solve.

CODE:
Echo __dir__; >= PHP 5.3

?: operator

Handy?: 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 ()

New Magic Method __callstatic, features similar to __call, but only valid for static methods.

CODE:
Class Helper {
static function __callstatic ($name, $args) {
echo $name. ' ('. Implode (', ', $args). ') ';
}
}
Helper::test ("foo", "Bar"); Test (Foo,bar)

Dynamic Invoke static method

Dynamic invocation of static methods? static and dynamic combination.

CODE:
Class Helper {
static function foo () {echo __method__;}
}
$a = "helper";
$b = "Foo";
$a:: $b (); Helper::foo

Late Static Binding

If you don't know how to translate it, you may be able to leave it easier to understand. The timing of event handling for static methods has changed, previously in compile-time processing, and is now performed during execution.

Before PHP 5.3, the following code will output a A, but this is not what we want, the WhoAmI method has been redefined in class B, and it should output B to fit the thinking we take for granted.

CODE:
Class A {
public static function WhoAmI () {
Echo __class__;
}
public static function identity () {
Self::whoami ();
}
}
Class B extends A {
public static function WhoAmI () {
Echo __class__;
}
}
B::identity (); A <--PHP <5.3

The following code uses Static::whoami () to invoke the static method. After PHP 5.3, because the __class__ is processed during the execution period, this example can successfully catch CLASS B.

CODE:
Class A {
public static function WhoAmI () {
Echo __class__;
}
public static function identity () {
Static::whoami ();
}
}
Class B extends A {
public static function WhoAmI () {
Echo __class__;
}
}
B::identity (); B <-->= PHP 5.3

Mysqlnd

Mysqlnd becomes the default MySQL driver in PHP 5.3, and it has the following advantages:

Mysqlnd easier to compile: because it's a part of the PHP source tree
Mysqlnd and PHP internal mechanisms are more tightly integrated and are optimized for MySQL-driven
Mysqlnd saves more memory and, from test results, saves 40% more memory than traditional MySQL extensions
Mysqlnd faster
MYSQLND provides a wealth of performance statistics features
MYSQLND uses PHP license to avoid unnecessary copyright disputes

This change should also take effect on both MySQL and pdo_mysql extensions.

What's mysqlnd?

Mysqlnd is the MySQL original PHP driver

But Pdo_mysql temporarily does not support MYSQLND, currently only MySQL (i) extension can be used to

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.