PHP 7.4.x 廢棄的功能

PHP 核心中廢棄的功能

沒(méi)有顯式括號(hào)的嵌套三元運(yùn)算符

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

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

大括號(hào)訪(fǎng)問(wèn)數(shù)組和字符串索引

使用大括號(hào)訪(fǎng)問(wèn)數(shù)組及字符串索引的方式已被廢棄。請(qǐng)使用 $var[$idx] 的語(yǔ)法來(lái)替代 $var{$idx}

(real) 類(lèi)型和 is_real() 函數(shù)

(real) 類(lèi)型已被廢棄,請(qǐng)使用 (float) 來(lái)替代。

同時(shí)被廢棄的還有 is_real() 函數(shù),請(qǐng)使用 is_float() 來(lái)替代。

Unbinding $this when $this is used

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

parent 關(guān)鍵詞在沒(méi)父類(lèi)的類(lèi)中使用

在沒(méi)有父類(lèi)的類(lèi)中使用 parent 關(guān)鍵詞已被廢棄,并且在將來(lái)的 PHP 版本中將會(huì)拋出一個(gè)編譯錯(cuò)誤。目前只在運(yùn)行時(shí)訪(fǎng)問(wèn)父類(lèi)時(shí)才會(huì)產(chǎn)生錯(cuò)誤。

allow_url_include INI 選項(xiàng)

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

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

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

在對(duì)象中使用 array_key_exists()

在一個(gè)對(duì)象中使用 array_key_exists() 已被廢棄。請(qǐng)使用 isset()property_exists() 來(lái)替代。

魔術(shù)引號(hào)函數(shù)

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

hebrevc() 函數(shù)

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

convert_cyr_string() 函數(shù)

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

money_format() 函數(shù)

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

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ù)順序的特性已被廢棄,請(qǐng)使用 implode($glue, $parts) 來(lái)替代 implode($parts, $glue)。

COM

導(dǎo)入類(lèi)型庫(kù)的大小寫(xiě)不敏感的常量注冊(cè)已被廢棄。

Filter

FILTER_SANITIZE_MAGIC_QUOTES 已被廢棄,使用 FILTER_SANITIZE_ADD_SLASHES 來(lái)替代。

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ù)已被廢棄??刂祈?yè)面操作可以使用 ldap_search() 替代。

Reflection

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

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() 中不再可用,因?yàn)樵摮A吭?glibc 中已被廢棄。