Summary of new features of PHP5.3, new features of php5.3_PHP tutorial

WBOY
Release: 2016-07-12 08:59:16
Original
769 people have browsed it

Summary of new features of PHP5.3, new features of php5.3

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 class, function and constant name conflicts

2. Static binding. When inheriting, 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 functions can also be used as the value of variables

$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 functions are currently implemented through the Closure class. It is currently unstable 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. The 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 be helpful to everyone in PHP programming.

Articles you may be interested in:

  • Compile and install PHP5.3 development environment under Ubuntu12
  • Solution to the problem that php5.3 cannot connect to mssql database
  • How to connect to sqlserver2000 in versions after php5.3
  • A summary of obsolete and expired functions of PHP5.3 and 5.5
  • Use pthreads to achieve true PHP multi-threading (requires PHP5.3 or above)
  • Introduction and examples of php5.3 goto function
  • php5.3 does not support session_register() Solutions for this function to be enabled
  • Notes on php5.3 notes
  • Summary of obsolete functions in php5.3
  • PHP5.3.1 no longer supports ISAPI

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1099064.htmlTechArticleSummary of new features of PHP5.3, new features of php5.3 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 conflict between class, function and constant names...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!