之前版本中,number_format()
有可能會(huì)返回 -0
。雖然這是符合 IEEE 754
規(guī)范的,但是這樣會(huì)導(dǎo)致可讀性不好,新版本中會(huì)將這樣的負(fù)數(shù)去掉。
<?php
var_dump(number_format(-0.01)); // 新版本輸出 string(1) "0" 舊版本輸出 string(2) "-0"
將數(shù)組轉(zhuǎn)換為對(duì)象,或?qū)?duì)象轉(zhuǎn)換為數(shù)組時(shí),數(shù)字鍵現(xiàn)在得到了更好的處理(無(wú)論是通過(guò)顯式轉(zhuǎn)換還是通過(guò) settype() 函數(shù))。
這意味著現(xiàn)在可以訪(fǎng)問(wèn)數(shù)組中的整數(shù)(或者說(shuō)是字符串整數(shù))鍵,這些鍵會(huì)映射到對(duì)象中:
<?php
// array to object
$arr = [0 => 1];
$obj = (object)$arr;
var_dump(
$obj,
$obj->{'0'}, // 新寫(xiě)法
$obj->{0} // 新寫(xiě)法
);
以上例程會(huì)輸出:
object(stdClass)#1 (1) { ["0"]=> // string key now, rather than integer key int(1) } int(1) int(1)
從對(duì)象轉(zhuǎn)換成的數(shù)組中的整數(shù)(或者說(shuō)是字符串整數(shù))鍵現(xiàn)在也可以直接訪(fǎng)問(wèn):
<?php
// object to array
$obj = new class {
public function __construct()
{
$this->{0} = 1;
}
};
$arr = (array)$obj;
var_dump(
$arr,
$arr[0], // 新寫(xiě)法
$arr['0'] // 新寫(xiě)法
);
以上例程會(huì)輸出:
array(1) { [0]=> // integer key now, rather than string key int(1) } int(1) int(1)
null
參數(shù)
之前版本中,傳遞 null
給 get_class()
函數(shù)將返回當(dāng)前類(lèi)名。在新版本中,此行為會(huì)拋出一個(gè)
E_WARNING
錯(cuò)誤。如果想實(shí)現(xiàn)與之前版本同樣的效果,請(qǐng)不要傳遞任何參數(shù)進(jìn)來(lái)。
對(duì)非可數(shù)類(lèi)型調(diào)用 count()(或
sizeof())函數(shù),會(huì)拋出一個(gè)
E_WARNING
錯(cuò)誤。
<?php
var_dump(
count(null), // NULL is not countable
count(1), // integers are not countable
count('abc'), // strings are not countable
count(new stdclass), // objects not implementing the Countable interface are not countable
count([1,2]) // arrays are countable
);
以上例程會(huì)輸出:
Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d int(0) int(1) int(1) int(1) int(2)
As part of the long-term migration away from resources, the Hash extension has been updated to use objects instead of resources. The change should be seamless for PHP developers, except for where is_resource() checks have been made (which will need updating to is_object() instead).
下列默認(rèn)選項(xiàng)被修改:
tls://
默認(rèn)為 TLSv1.0 or TLSv1.1 or TLSv1.2
ssl://
成為 tls://
的別名
STREAM_CRYPTO_METHOD_TLS_*
常量默認(rèn)為 TLSv1.0
或 TLSv1.1 + TLSv1.2,替代之前的 TLSv1.0
之前版本中,如果在一個(gè)閉包資源中使用 gettype()
會(huì)返回字符串 "unknown type"
,現(xiàn)在將會(huì)返回字符
"resource (closed)"
。
之前版本中,對(duì) __PHP_Incomplete_Class
調(diào)用 is_object() 函數(shù)會(huì)返回
false
,現(xiàn)在會(huì)返回 true
。
調(diào)用未定義的常量,現(xiàn)在會(huì)拋出一個(gè)
E_WARNING
錯(cuò)誤(之前版本中為 E_NOTICE
)。在下一個(gè)
PHP 大版本中,將會(huì)拋出一個(gè)
Error 錯(cuò)誤。
官方支持的最低 Windows 版本為 Windows 7/Server 2008 R2。
Compatibility checks upon default trait property values will no longer perform casting.
object
保留字的變化
object
在之前的 PHP 7.0 版本
中被聲明為軟保留字(soft-reserved)。現(xiàn)在變更為強(qiáng)制保留字,禁止在任何類(lèi)或接口中使用該名稱(chēng)。
NetWare 已不再被支持。
SORT_STRING
While array_unique() with SORT_STRING
formerly copied the array and removed non-unique elements (without packing
the array afterwards), now a new array is built by adding the
unique elements. This can result in different numeric indexes.
The bcmod() function no longer truncates fractional
numbers to integers. As such, its behavior now follows
fmod(), rather than the %
operator.
For example bcmod('4', '3.5')
now returns
0.5
instead of 1
.
The hash_hmac(), hash_hmac_file(),
hash_pbkdf2(), and hash_init() (with
HASH_HMAC
) functions no longer accept non-cryptographic
hashes.
The json_decode() function option,
JSON_OBJECT_AS_ARRAY
, is now used if the second
parameter (assoc) is null
. Previously,
JSON_OBJECT_AS_ARRAY
was always ignored.
Sequences generated by rand() and mt_rand() for a specific seed may differ from PHP 7.1 on 64-bit machines (due to the fixing of a modulo bias bug in the implementation).
sql.safe_mode
ini 選項(xiàng)移除
sql.safe_mode
ini 設(shè)置項(xiàng)已被移除。
The zone
element of the array returned by date_parse() and
date_parse_from_format() represents seconds instead of
minutes now, and its sign is inverted. For instance -120
is now 7200
.
As of PHP 7.2.34, the names of incoming cookies are no longer url-decoded for security reasons.