php+needle,PHP: 新特性 - Manual

新特性

PHP 核心中的新特性

命名参数

注解(Attributes)

新增注解的功能。

构造器属性提升(Constructor Property Promotion)

新增构造器属性提升功能(在构造函数中声明类的属性)。

联合类型

Match 表达式

Nullsafe 运算符

新增 Nullsafe 运算符(?->)。

其他新特性

新增 WeakMap 类。

新增 ValueError 类。

现在,只要类型兼容,任意数量的函数参数都可以用一个可变参数替换。

例如允许编写下面的代码:

public functionmethod(int $many,string $parameters,$here) {}

}

classBextendsA{

public functionmethod(...$everything) {}

}?>

static ("后期静态绑定"中) 可以作为返回类型:

public functioncreate(): static {

return new static();

}

}?>

现在可以通过 $object::class 获取类名,返回的结果和 get_class($object) 一致。

new、instanceof 可用于任何表达式,

用法为 new (expression)(...$args) 和 $obj instanceof (expression)。

添加对一些变量语法一致性的修复,例如现在能够编写

Foo::BAR::$baz。

添加 Stringable interface,

当一个类定义 __toString() 方法后会自动实现该接口。

Trait 可以定义私有抽象方法(abstract private method)。

类必须实现 trait 定义的该方法。

可作为表达式使用 throw。

使得可以编写以下用法:

$fn=fn() => throw newException('Exception in arrow function');$user=$session->user?? throw newException('Must have user');

参数列表中的末尾逗号为可选。

}

现在允许 catch (Exception) 一个 exception 而无需捕获到变量中。

支持

Private methods declared on a parent class no longer enforce any inheritance rules on the methods

of a child class (with the exception of final private constructors).

The following example illustrates which restrictions have been removed:

private functionmethod1() {}

private functionmethod2() {}

private static functionmethod3() {}// Throws a warning, as "final" no longer has an effect:private final functionmethod4() {}

}

classChildClassextendsParentClass{// All of the following are now allowed, even though the modifiers aren't

// the same as for the private methods in the parent class.public abstract functionmethod1() {}

public static functionmethod2() {}

public functionmethod3() {}

public functionmethod4() {}

}?>

(int) $resource. It provides the same functionality under a clearer API.

Date and Time

The DateTime format specifier p has been added, which is the same as

P but returns Z rather than +00:00

for UTC.

DOM

DOMParentNode and DOMChildNode with

new traversal and manipulation APIs have been added.

Filter

FILTER_VALIDATE_BOOL has been added as an alias for

FILTER_VALIDATE_BOOLEAN. The new name is preferred, as it uses the canonical

type name.

Enchant

FPM

Added a new option pm.status_listen that allows getting the status from

different endpoint (e.g. port or UDS file) which is useful for getting the status when all

children are busy with serving long running requests.

Hash

HashContext objects can now be serialized.

Internationalization Functions

The IntlDateFormatter::RELATIVE_FULL,

IntlDateFormatter::RELATIVE_LONG,

IntlDateFormatter::RELATIVE_MEDIUM, and

IntlDateFormatter::RELATIVE_SHORT

constants have been added.

LDAP

ldap_count_references() has been added, which returns the number

of reference messages in a search result.

OPcache

If the opcache.record_warnings ini setting is

enabled, OPcache will record compile-time warnings and replay them on the next include, even if

it is served from cache.

OpenSSL

Added Cryptographic Message Syntax (CMS) (» RFC 5652)

support composed of functions for encryption, decryption, signing, verifying and reading. The API

is similar to the API for PKCS #7 functions with an addition of new encoding constants:

OPENSSL_ENCODING_DER, OPENSSL_ENCODING_SMIME

and OPENSSL_ENCODING_PEM:

Regular Expressions (Perl-Compatible)

SQLite3

Standard Library

haystack contains,

starts with or ends with needle, respectively.

Inf,

-Inf or NaN.

get_debug_type() has been added, which returns a type useful for error messages. Unlike

%h and

%H format specifiers. These are the same as %g and

%G, but always use "." as the decimal separator, rather

than determining it through the LC_NUMERIC locale.

"*" as width or

precision, in which case the width/precision is passed as an argument to printf. This also allows

using precision -1 with %g, %G,

%h and %H. For example, the following code can be used to

reproduce PHP's default floating point formatting:

printf("%.*H", (int)ini_get("precision"),$float);printf("%.*H", (int)ini_get("serialize_precision"),$float);?>

stdin, stdout and stderr to the

same PTY:

$proc=proc_open($command, [['pty'], ['pty'], ['pty']],$pipes);?>

stdin, stdout and

stderr:

$proc=proc_open($command, [['socket'], ['socket'], ['socket']],$pipes);?>

Unlike pipes, sockets do not suffer from blocking I/O issues on Windows. However, not all

programs may work correctly with stdio sockets.

Sorting functions are now stable, which means that equal-comparing elements will retain their

original order.

The flag parameter of bool rather than an int.

Tokenizer

PhpToken adds an object-based interface to the tokenizer. It provides a

more uniform and ergonomic representation, while being more memory efficient and faster.

Zip

The Zip extension has been updated to version 1.19.1.

New

New

New

New

New

The ZipArchive::lastId property to get the index value of

the last added entry has been added.

Errors can now be checked after an archive has been closed using the

ZipArchive::status and

ZipArchive::statusSys properties, or the

The 'remove_path' option of 'add_path' option), whereas formerly it was treated as a

directory name.

Optional compression / encryption features are now listed in phpinfo.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值