Home > Backend Development > PHP Tutorial > Summary of new features of PHP53

Summary of new features of PHP53

WBOY
Release: 2016-07-29 09:03:45
Original
1141 people have browsed it

This article summarizes and analyzes the new features of PHP5.3. Share it with everyone for your reference, the details are as follows:

1. Namespace solves the problem of conflict between class, function and constant names

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

class A {
  public static function who() {
    echo __CLASS__;
  }
  public static function test() {
    static::who(); // 后期静态绑定从这里开始
  }
}
class B extends A {
  public static function who() {
    echo __CLASS__;
  }
}
B::test();

Copy after login

3. Anonymous functions, also called closure functions, allow you to temporarily create a function without a specified name. Most commonly used as callback function

//匿名函数做回调函数
uasort($arr ,function($a, $b){
})

Copy after login

Closure function can also be used as the value of a variable

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

Copy after login

PHP will automatically convert the expression into an object instance of the built-in class Closure

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

Copy after login

Anonymous function currently It is implemented through the Closure class. It is not yet stable and not suitable for official development

3. ?: operator

$a = 0; 
$b = 2;
ee($a ?: $b); # 2 类似js中的 ||

Copy after login

4. New constant __DIR_

5. New garbage collection mechanism solves the problem of circular references

gc_enable(); // 激活循环引用收集器,默认开启
var_dump(gc_collect_cycles()); // 强制回收已无效的变量
gc_disable(); // 禁用GC

Copy after login

Readers who are interested in more PHP-related content can check out the special topics of this site: "Introduction Tutorial on PHP Basic Syntax", "Summary of PHP Error and Exception Handling Methods" and "Summary of Common PHP Functions and Techniques"

I hope this article will explain It will be helpful to everyone in PHP programming.

The above has introduced a summary of the new features of PHP53, including relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template