Table of Contents
PHP5.3新特性小结,php5.3新特性
您可能感兴趣的文章:
Home php教程 php手册 PHP5.3新特性小结,php5.3新特性

PHP5.3新特性小结,php5.3新特性

Jun 13, 2016 am 08:46 AM
php5 new features

PHP5.3新特性小结,php5.3新特性

本文总结分析了PHP5.3新特性。分享给大家供大家参考,具体如下:

1、命名空间 解决了类,函数和常量名冲突的问题

2、静态绑定 继承时父类可以直接调用子类重写父类的方法

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、匿名函数,也叫闭包函数(closures),允许 临时创建一个没有指定名称的函数。最经常用作回调函数

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

Copy after login

闭包函数也可以作为变量的值来使用

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

Copy after login

PHP会自动把表达式转换成内置类Closure的 对象实例

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

Copy after login

匿名函数目前是通过Closure类来实现的。目前还不稳定,不适用于正式开发

3、?: 操作符

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

Copy after login

4、新增常量 __DIR_

5、新的垃圾回收机制,解决了循环引用的问题

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

Copy after login

更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP基本语法入门教程》、《PHP错误与异常处理方法总结》及《php常用函数与技巧总结》

希望本文所述对大家PHP程序设计有所帮助。

您可能感兴趣的文章:

  • Ubuntu12下编译安装PHP5.3开发环境
  • php5.3不能连接mssql数据库的解决方法
  • php5.3以后的版本连接sqlserver2000的方法
  • PHP5.3与5.5废弃与过期函数整理汇总
  • 使用pthreads实现真正的PHP多线程(需PHP5.3以上版本)
  • php5.3 goto函数介绍和示例
  • php5.3 不支持 session_register() 此函数已启用的解决方法
  • php5.3 注意事项说明
  • php5.3 废弃函数小结
  • PHP5.3.1 不再支持ISAPI
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the difference between php5 and php8 What is the difference between php5 and php8 Sep 25, 2023 pm 01:34 PM

The differences between php5 and php8 are in terms of performance, language structure, type system, error handling, asynchronous programming, standard library functions and security. Detailed introduction: 1. Performance improvement. Compared with PHP5, PHP8 has a huge improvement in performance. PHP8 introduces a JIT compiler, which can compile and optimize some high-frequency execution codes, thereby improving the running speed; 2. Improved language structure, PHP8 introduces some new language structures and functions. PHP8 supports named parameters, allowing developers to pass parameter names instead of parameter order, etc.

How to change port 80 in php5 How to change port 80 in php5 Jul 24, 2023 pm 04:57 PM

How to change port 80 in php5: 1. Edit the port number in the Apache server configuration file; 2. Edit the PHP configuration file to ensure that PHP works on the new port; 3. Restart the Apache server, and the PHP application will start running on the new port. run on the port.

PHP 8.3 released: new features at a glance PHP 8.3 released: new features at a glance Nov 27, 2023 pm 12:52 PM

PHP8.3 released: Overview of new features As technology continues to develop and needs change, programming languages ​​are constantly updated and improved. As a scripting language widely used in web development, PHP has been constantly improving to provide developers with more powerful and efficient tools. The recently released PHP 8.3 version brings many long-awaited new features and improvements. Let’s take a look at an overview of these new features. Initialization of non-null properties In past versions of PHP, if a class property was not explicitly assigned a value, its value

A guide to learn the new features of PHP8 and gain an in-depth understanding of the latest technology A guide to learn the new features of PHP8 and gain an in-depth understanding of the latest technology Dec 23, 2023 pm 01:16 PM

An in-depth analysis of the new features of PHP8 to help you master the latest technology. As time goes by, the PHP programming language has been constantly evolving and improving. The recently released PHP8 version provides developers with many exciting new features and improvements, bringing more convenience and efficiency to our development work. In this article, we will analyze the new features of PHP8 in depth and provide specific code examples to help you better master these latest technologies. JIT compiler PHP8 introduces JIT (Just-In-Time) compilation

What are the new features of php8 What are the new features of php8 Sep 25, 2023 pm 01:34 PM

New features of php8 include JIT compiler, type deduction, named parameters, union types, properties, error handling improvements, asynchronous programming support, new standard library functions and anonymous class extensions. Detailed introduction: 1. JIT compiler, PHP8 introduces the JIT compiler, which is an important performance improvement. The JIT compiler can compile and optimize some high-frequency execution codes in real time, thereby improving the running speed; 2. Type derivation , PHP8 introduces the type inference function, allowing developers to automatically deduce the type of variables when declaring variables, etc.

Interpretation of new features of Go language: making programming more efficient Interpretation of new features of Go language: making programming more efficient Mar 10, 2024 pm 12:27 PM

[Interpretation of new features of Go language: To make programming more efficient, specific code examples are needed] In recent years, Go language has attracted much attention in the field of software development, and its simple and efficient design concept has attracted more and more developers. As a statically typed programming language, Go language continues to introduce new features to improve development efficiency and simplify the code writing process. This article will provide an in-depth explanation of the latest features of the Go language and discuss how to experience the convenience brought by these new features through specific code examples. Modular development (GoModules) Go language from 1

An overview of the new features of CSS3: How to use CSS3 to achieve transition effects An overview of the new features of CSS3: How to use CSS3 to achieve transition effects Sep 09, 2023 am 11:27 AM

Overview of the new features of CSS3: How to use CSS3 to achieve transition effects CSS3 is the latest version of CSS. Among the many new features, the most interesting and practical one should be the transition effect. Transition effects can make our pages smoother and more beautiful during interaction, giving users a good visual experience. This article will introduce the basic usage of CSS3 transition effects, with corresponding code examples. transition-property attribute: Specify the CSS property transition effect that needs to be transitioned

Overview of the new features of CSS3: How to use CSS3 to achieve horizontally centered layout Overview of the new features of CSS3: How to use CSS3 to achieve horizontally centered layout Sep 09, 2023 pm 04:09 PM

Overview of the new features of CSS3: How to use CSS3 to achieve horizontally centered layout In web design and layout, horizontally centered layout is a common requirement. In the past, we often used complex JavaScript or CSS tricks to achieve this. However, CSS3 introduced some new features that make horizontally centered layouts simpler and more flexible. This article will introduce some new features of CSS3 and provide some code examples to demonstrate how to use CSS3 to achieve horizontally centered layout. 1. Use flexbox to layout fle

See all articles