php 5.6新特性
PHP5.6已经发布Alpha版,预示着下一个大版本的升级即将到来,PHP5.6带来了哪些新特性?本文将介绍这些特性,并讨论它们可以给开发者带来哪些好处。 常量标量表达式(Constant scalar expressions) 在常量、属性声明和函数参数默认值声明时,以前版本只允许常
PHP5.6已经发布Alpha版,预示着下一个大版本的升级即将到来,PHP5.6带来了哪些新特性?本文将介绍这些特性,并讨论它们可以给开发者带来哪些好处。
常量标量表达式(Constant scalar expressions)
在常量、属性声明和函数参数默认值声明时,以前版本只允许常量值,PHP5.6开始允许使用包含数字、字符串字面值和常量的标量表达式。
上面代码输出:
1 |
|
可变参数函数(Variadic functions via ...)
可变参数函数 的实现, 不再依赖func_get_args()函数,现在可以通过新增的操作符 <span style="font-size: 14px;">...</span>
更简洁地实现。
1
2
3
4
5
6
7
8
9
10
<code style=
"padding: 0.5em; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; display: block;"
><?php
function
f(
$req
,
$opt
= null, ...
$params
) {
// $params is an array containing the remaining arguments.
printf(
'$req: %d; $opt: %d; number of params: %d'
.
"\n"
,
$req
,
$opt
,
count
(
$params
));
}
f(1);
f(1, 2);
f(1, 2, 3);
f(1, 2, 3, 4);
f(1, 2, 3, 4, 5);</code></code>
Copy after login
1 2 3 4 5 6 7 8 9 10 |
|
上面代码输出:
1 2 3 4 5 |
|
参数解包功能(Argument unpacking via ...)
在调用函数的时候,通过 <span style="font-size: 14px;">...</span>
操作符可以把数组或者可遍历对象解包到参数列表,这和Ruby等语言中的扩张(splat)操作符类似。
1 2 3 4 5 6 |
|
上面代码输出:
1 |
|
导入函数和常量(use function and use const)
<span style="font-size: 14px;">use</span>
操作符开始支持函数和常量的导入。 <span style="font-size: 14px;">use function</span>
和 <span style="font-size: 14px;">use const</span>
结构的用法的示例:
1 2 3 4 5 6 7 8 9 10 11 |
|
上面代码输出:
1 2 |
|
phpdbg
PHP自带了一个交互式调试器phpdbg,它是一个SAPI模块,更多信息参考phpdbg文档 。
php://input可以被复用
<span style="font-size: 14px;">php://input</span>
开始支持多次打开和读取,这给处理POST数据的模块的内存占用带来了极大的改善。
大文件上传支持
可以上传超过2G的大文件。
GMP支持操作符重载
GMP 对象支持操作符重载和转换为标量,改善了代码的可读性,如:
1 2 3 4 5 6 7 8 9 10 11 |
|
新增gost-crypto哈希算法
采用CryptoPro S-box tables实现了 <span style="font-size: 14px;">gost-crypto</span>
哈希算法,详情参考 RFC 4357, section 11.2 。
SSL/TLS改进
OpenSSL扩展新增证书指纹的提取和验证功能,<span style="font-size: 14px;">openssl_x509_fingerprint()</span>
用于提取X.509证书的指纹,SSL stream context 选项: <span style="font-size: 14px;">capture_peer_cert</span>
用于获取对方X.509证书;<span style="font-size: 14px;">peer_fingerprint</span>
用于断言对方证书和给定的指纹匹配。
另外,可以通过SSL流上下文选项 <span style="font-size: 14px;">crypto_method</span>
指定加密方法,如SSLv3或TLS,目前支持的选项值包括STREAM_CRYPTO_METHOD_SSLv2_CLIENT, STREAM_CRYPTO_METHOD_SSLv3_CLIENT, STREAM_CRYPTO_METHOD_SSLv23_CLIENT (默认), or STREAM_CRYPTO_METHOD_TLS_CLIENT。
转:http://wulijun.github.io/2014/01/25/whats-new-in-php-5-6.html
原文地址:php 5.6新特性, 感谢原作者分享。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide
