PHP 7.4.x 廢棄的功能

PHP 核心中廢棄的功能

沒有顯式括號的嵌套三元運算符

嵌套的三元操作中,必須明確使用顯式括號來決定操作的順序。以前,如果不使用括號,在大多數(shù)情況下,左關(guān)聯(lián)性不會導(dǎo)致預(yù)期的行為。

<?php
5;   // deprecated
(3) ? 5// ok
: (5); // ok
?>

大括號訪問數(shù)組和字符串索引

使用大括號訪問數(shù)組及字符串索引的方式已被廢棄。請使用 $var[$idx] 的語法來替代 $var{$idx}。

(real) 類型和 is_real() 函數(shù)

(real) 類型已被廢棄,請使用 (float) 來替代。

同時被廢棄的還有 is_real() 函數(shù),請使用 is_float() 來替代。

Unbinding $this when $this is used

Unbinding $this of a non-static closure that uses $this is deprecated.

parent 關(guān)鍵詞在沒父類的類中使用

在沒有父類的類中使用 parent 關(guān)鍵詞已被廢棄,并且在將來的 PHP 版本中將會拋出一個編譯錯誤。目前只在運行時訪問父類時才會產(chǎn)生錯誤。

allow_url_include INI 選項

配置文件中的 allow_url_include 選項被廢棄。如果啟用了該選項,將會產(chǎn)生一個棄用通知。

基礎(chǔ)轉(zhuǎn)換函數(shù)中的無效字符處理

在下面這些基礎(chǔ)轉(zhuǎn)換函數(shù)中,base_convert(), bindec(), octdec()hexdec() 如果傳入了非法字符,將會拋出一個棄用通知。函數(shù)會忽略掉無效字符后正常返回結(jié)果。前導(dǎo)空格和尾部空格,以及類型為 0x (取決于基數(shù)) 被允許傳入。

在對象中使用 array_key_exists()

在一個對象中使用 array_key_exists() 已被廢棄。請使用 isset()property_exists() 來替代。

魔術(shù)引號函數(shù)

魔術(shù)引號函數(shù) get_magic_quotes_gpc()get_magic_quotes_runtime() 已被廢棄。它們將永遠(yuǎn)返回 false。

hebrevc() 函數(shù)

hebrevc() 函數(shù)已被廢棄。 可以用 nl2br(hebrev($str)) 來替代,更好的方法是啟用 Unicode RTL 來支持。

convert_cyr_string() 函數(shù)

convert_cyr_string() 函數(shù)已被廢棄??梢杂?mb_convert_string()iconv()UConverter 替代。

money_format() 函數(shù)

money_format() 函數(shù)已被廢棄。 可以用更國際化的 NumberFormatter 功能來替代。

ezmlm_hash() 函數(shù)

ezmlm_hash() 函數(shù)已被廢棄。

restore_include_path() 函數(shù)

restore_include_path() 函數(shù)已被廢棄??梢杂?ini_restore('include_path') 替代。

Implode 函數(shù)的參數(shù)順序

implode() 允許反轉(zhuǎn)參數(shù)順序的特性已被廢棄,請使用 implode($glue, $parts) 來替代 implode($parts, $glue)。

COM

導(dǎo)入類型庫的大小寫不敏感的常量注冊已被廢棄。

Filter

FILTER_SANITIZE_MAGIC_QUOTES 已被廢棄,使用 FILTER_SANITIZE_ADD_SLASHES 來替代。

Multibyte String

Passing a non-string pattern to mb_ereg_replace() is deprecated. Currently, non-string patterns are interpreted as ASCII codepoints. In PHP 8, the pattern will be interpreted as a string instead.

Passing the encoding as 3rd parameter to mb_strrpos() is deprecated. Instead pass a 0 offset, and encoding as 4th parameter.

Lightweight Directory Access Protocol

ldap_control_paged_result_response()ldap_control_paged_result() 函數(shù)已被廢棄。控制頁面操作可以使用 ldap_search() 替代。

Reflection

調(diào)用 ReflectionType::__toString() 現(xiàn)在將會拋出一個棄用通知。 該方法從 PHP 7.1 開始,在 ReflectionNamedType::getName() 的文檔中已經(jīng)被聲明廢棄,但是由于技術(shù)原因,并沒有拋出棄用通知。

The export() methods on all Reflection classes are deprecated. Construct a Reflection object and convert it to string instead:

<?php
// ReflectionClass::export(Foo::class, false) is:
echo new ReflectionClass(Foo::class), "\n";

// $str = ReflectionClass::export(Foo::class, true) is:
$str = (string) new ReflectionClass(Foo::class);
?>

Socket

常量 AI_IDN_ALLOW_UNASSIGNEDAI_IDN_USE_STD3_ASCII_RULESsocket_addrinfo_lookup() 中不再可用,因為該常量在 glibc 中已被廢棄。