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