php7支持 new吗,PHP7.4 New Features 新特性

- Core:

. Added support for typed properties. For example:

class User {

public int $id;

public string $name;

}

This will enforce that $user->id can only be assigned integer and

$user->name can only be assigned strings. For more information see the

RFC: https://wiki.php.net/rfc/typed_properties_v2

. Added support for arrow functions with implicit by-value scope binding.

For example:

$factor = 10;

$nums = array_map(fn($num) => $num * $factor, $nums);

RFC: https://wiki.php.net/rfc/arrow_functions_v2

. Added support for limited return type covariance and argument type

contravariance. The following code will now work:

class A {}

class B extends A {}

class Producer {

public function method(): A {}

}

class ChildProducer extends Producer {

public function method(): B {}

}

Full variance support is only available if autoloading is used. Inside a

single file only non-cyclic type references are possible, because all

classes need to be available before they are referenced.

RFC: https://wiki.php.net/rfc/covariant-returns-and-contravariant-parameters

. Added support for coalesce assign (??=) operator. For example:

$array['key'] ??= computeDefault();

// is roughly equivalent to

if (!isset($array['key'])) {

$array['key'] = computeDefault();

}

RFC: https://wiki.php.net/rfc/null_coalesce_equal_operator

. Added support for unpacking inside arrays. For example:

$arr1 = [3, 4];

$arr2 = [1, 2, ...$arr1, 5];

// $arr2 == [1, 2, 3, 4, 5]

RFC: https://wiki.php.net/rfc/spread_operator_for_array

. Support for WeakReferences has been added.

RFC: https://wiki.php.net/rfc/weakrefs

. Throwing exceptions from __toString() is now permitted. Previously this

resulted in a fatal error. Existing recoverable fatals in string conversions

have been converted to Error exceptions.

RFC: https://wiki.php.net/rfc/tostring_exceptions

- CURL:

. CURLFile now supports stream wrappers in addition to plain file names, if

the extension has been built against libcurl >= 7.56.0.  The streams may

need to be seekable.

- Filter:

. The FILTER_VALIDATE_FLOAT filter now supports the min_range and max_range

options, with the same semantics as FILTER_VALIDATE_INT.

- FFI:

. A new extension which provides a simple way to call native functions, access

native variables and create/access data structures defined in C libraries.

RFC: https://wiki.php.net/rfc/ffi

- GD:

. Added the "scatter" image filter (IMG_FILTER_SCATTER) to apply a scatter

filter to images. This filter has the following prototype:

imagefilter($im, IMG_FILTER_SCATTER, int $sub, int $plus, array $colors = []);

The $colors array can be populated with a set of indexed colors where to

apply the scatter pixel shifting on.

Note, the result of this filter is always random.

- Hash:

. Added "crc32c" hash using Castagnoli's polynomial. This crc32 variant is

used by storage systems, such as iSCSI, SCTP, Btrfs and ext4.

- Mbstring:

. Added mb_str_split() function, which provide the same functionality as

str_split(), but operating on code points rather than bytes.

RFC: https://wiki.php.net/rfc/mb_str_split

- OPcache:

. Support for preloading code has been added.

RFC: https://wiki.php.net/rfc/preload

- PCRE:

. The preg_replace_callback() and preg_replace_callback_array() functions now

accept an additional $flags argument, with support for the

PREG_OFFSET_CAPTURE and PREG_UNMATCHED_AS_NULL flags. This influences the

format of the matches array passed to to the callback function.

- PDO_OCI:

. PDOStatement::getColumnMeta() is now available

- PDO_SQLite:

. PDOStatement::getAttribute(PDO::SQLITE_ATTR_READONLY_STATEMENT) allows to

check whether this statement is read-only, i.e. whether it doesn't modify

the database.

- Standard:

. strip_tags() now also accepts an array of allowed tags: Instead of

strip_tags($str, '

') you can now write strip_tags($str, ['a', 'p']).

. A new mechanism for custom object serialization has been added, which

uses two new magic methods:

// Returns array containing all the necessary state of the object.

public function __serialize(): array;

// Restores the object state from the given data array.

public function __unserialize(array $data): void;

The new serialization mechanism supersedes the Serializable interface,

which will be deprecated in the future.

RFC: https://wiki.php.net/rfc/custom_object_serialization

. array_merge() and array_merge_recursive() may now be called without any

arguments, in which case they will return an empty array. This is useful

in conjunction with the spread operator, e.g. array_merge(...$arrays).

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值