New Features of PHP5.3 and new features of php5.3

Source: Internet
Author: User

New Features of PHP5.3 and new features of php5.3

This article summarizes and analyzes the new features of PHP5.3. We will share this with you for your reference. The details are as follows:

1. The namespace solves the conflict between classes, functions, and constant names.

2. When static binding inheritance, the parent class can directly call the subclass to override the parent class method.

Class A {public static function who () {echo _ CLASS __;} public static function test () {static: who (); // later static binding starts here} class B extends A {public static function who () {echo _ CLASS __;}} B: test ();

3. Anonymous functions, also called closures, allow temporary creation of a function without a specified name. Most often used as Callback Functions

// Callback function for anonymous functions uasort ($ arr, function ($ a, $ B ){})

Closure functions can also be used as variable values.

$fn = function ($a) {  echo $a;};$fn(1);

PHP automatically converts the expression to an object instance with built-in Closure class.

$fn = function ($a) {  echo $a;};ee($fn);/** * Closure Object(  [parameter] => Array    (      [$a] =>     ))*/

Currently, anonymous functions are implemented through the Closure class. It is not stable yet and does not apply to formal development.

3 ,? : Operator

$ A = 0; $ B = 2; ee ($? : $ B); #2 |

4. Add a constant _ DIR _

5. The new garbage collection mechanism solves the problem of circular reference.

Gc_enable (); // activate the cyclic reference collector. var_dump (gc_collect_cycles () is enabled by default; // forcibly recycle the invalid variable gc_disable (); // disable GC

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.