日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > php >内容正文

php

new php,PHP: 新特性 - Manual

發(fā)布時(shí)間:2025/3/15 php 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 new php,PHP: 新特性 - Manual 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

新特性

PHP 核心中的新特性

屬性添加限定類型

類的屬性中現(xiàn)在支持添加指定的類型。

publicint?$id;

publicstring?$name;

}?>

上面的例子中,會(huì)強(qiáng)制要求 $user->id 只能為 int

類型,同時(shí) $user->name 只能為 string 類型。

箭頭函數(shù)

箭頭函數(shù) 提供了一種更簡(jiǎn)潔的定義函數(shù)的方法。

$factor=10;$nums=array_map(fn($n)?=>$n*$factor,?[1,2,3,4]);//?$nums?=?array(10,?20,?30,?40);?>

有限返回類型協(xié)變與參數(shù)類型逆變

以下代碼將不會(huì)正常工作:

classBextendsA{}

classProducer{

public?functionmethod():A{}

}

classChildProducerextendsProducer{

public?functionmethod():B{}

}?>

只有在使用自動(dòng)加載的情況下,才會(huì)有完整的差異支持。在一個(gè)文件內(nèi),只有非循環(huán)類型引用是可能的,因?yàn)樵谝弥?#xff0c;所有的類都需要可用。

空合并運(yùn)算符賦值

$array['key']???=computeDefault();//?等同于以下舊寫法if?(!isset($array['key']))?{$array['key']?=computeDefault();

}?>

數(shù)組展開操作

$parts=?['apple','pear'];$fruits=?['banana','orange',?...$parts,'watermelon'];//?['banana',?'orange',?'apple',?'pear',?'watermelon'];?>

數(shù)值文字分隔符

數(shù)字文字可以在數(shù)字之間包含下劃線。

6.674_083e-11;//?float299_792_458;//?decimal0xCAFE_F00D;//?hexadecimal0b0101_1111;//?binary?>

Weak references

Weak references allow the programmer to retain a reference to an object

that does not prevent the object from being destroyed.

允許從 __toString() 拋出異常

現(xiàn)在允許從 __toString()

拋出異常。之前的版本,將會(huì)導(dǎo)致一個(gè)致命錯(cuò)誤。新版本中,之前發(fā)生致命錯(cuò)誤的代碼,已經(jīng)被轉(zhuǎn)換為

Error 異常。

CURL

CURLFile now supports stream wrappers in addition

to plain file names, if the extension has been built against libcurl >= 7.56.0.

Filter

The FILTER_VALIDATE_FLOAT filter now supports the

min_range and max_range

options, with the same semantics as FILTER_VALIDATE_INT.

FFI

FFI is a new extension, which provides a simple way to call

native functions, access native variables, and create/access

data structures defined in C libraries.

GD

Added the IMG_FILTER_SCATTER image filter

to apply a scatter filter to images.

Hash

Added crc32c hash using Castagnoli's polynomial.

This CRC32 variant is used by storage systems, such as

iSCSI, SCTP, Btrfs and ext4.

Multibyte String

Added the

OPcache

新增 緩存預(yù)加載 特性。

Regular Expressions (Perl-Compatible)

The 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

The username and password can now be specified as part of the PDO DSN for

the mysql, mssql, sybase, dblib, firebird and oci drivers. Previously this

was only supported by the pgsql driver. If a username/password is specified

both in the constructor and the DSN, the constructor takes precedence.

It is now possible to escape question marks in SQL queries to avoid them

being interpreted as parameter placeholders. Writing ??

allows sending a single question mark to the database and e.g. use the

PostgreSQL JSON key exists (?) operator.

PDO_SQLite

PDOStatement::getAttribute(PDO::SQLITE_ATTR_READONLY_STATEMENT)

allows checking whether the statement is read-only, i.e. if it doesn't modify

the database.

PDO::setAttribute(PDO::SQLITE_ATTR_EXTENDED_RESULT_CODES, true)

enables the use of SQLite3 extended result codes in

SQLite3

Added SQLite3::lastExtendedErrorCode()

to fetch the last extended result code.

Added SQLite3::enableExtendedResultCodes($enable = true),

which will make

Standard

strip_tags() with array of tag names

strip_tags($str, '

')

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

Custom object serialization

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

uses two new magic methods: __serialize

and __unserialize.

The new serialization mechanism supersedes the

Serializable interface,

which will be deprecated in the future.

Array merge functions without arguments

array_merge(...$arrays).

proc_open(['php','-r','echo?"Hello?World\n";'],$descriptors,$pipes);?>

redirect and null descriptors.

<?php //?Like?2>&1?on?the?shellproc_open($cmd,?[1=>?['pipe','w'],2=>?['redirect',1]],$pipes);//?Like?2>/dev/null?or?2>nul?on?the?shellproc_open($cmd,?[1=>?['pipe','w'],2=>?['null']],$pipes);?>

argon2i(d) without libargon

總結(jié)

以上是生活随笔為你收集整理的new php,PHP: 新特性 - Manual的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。