如果帶有默認(rèn)值的參數(shù)后面跟著一個(gè)必要的參數(shù),那么默認(rèn)值就會(huì)無效。這在 PHP 8.0.0 中已被廢棄,通??梢酝ㄟ^刪除默認(rèn)值,不影響現(xiàn)有功能:
<?php
function test($a = [], $b) {} // 之前
function test($a, $b) {} // 之后
?>
這條規(guī)則的一個(gè)例外是 Type $param = null
形式的參數(shù),其中 null
的默認(rèn)值使得類型隱式為空。這種用法仍然是允許的,但仍建議使用顯式可空類型。
<?php
function test(A $a = null, $b) {} // 舊寫法,仍可用
function test(?A $a, $b) {} // 推薦寫法
?>
參數(shù) exclude_disabled
不能設(shè)置為 false
來調(diào)用 get_defined_functions(),該參數(shù)已被廢棄,不再起作用。
get_defined_functions() 絕不會(huì)再包含禁用的函數(shù)。
enchant_broker_set_dict_path() and enchant_broker_get_dict_path() are deprecated, because that functionality is neither available in libenchant < 1.5 nor in libenchant-2.
enchant_dict_add_to_personal() is deprecated; use enchant_dict_add() instead.
enchant_dict_is_in_session() is deprecated; use enchant_dict_is_added() instead.
enchant_broker_free() and enchant_broker_free_dict() are deprecated; unset the object instead.
The ENCHANT_MYSPELL
and ENCHANT_ISPELL
constants are
deprecated.
libxml_disable_entity_loader() has been deprecated. As libxml 2.9.0 is now
required, external entity loading is guaranteed to be disabled by default, and this function is
no longer needed to protect against XXE attacks, unless the (still vulnerable).
LIBXML_NOENT
is used.
In that case, it is recommended to refactor the code using
libxml_set_external_entity_loader() to suppress loading of external entities.
The constant PGSQL_LIBPQ_VERSION_STR
now has the same value as
PGSQL_LIBPQ_VERSION
, and thus is deprecated.
Function aliases in the pgsql extension have been deprecated. See the following list for which functions should be used instead:
Sort comparison functions that return true
or false
will now throw a deprecation warning, and
should be replaced with an implementation that returns an integer less than, equal to, or greater
than zero.
<?php
// Replace
usort($array, fn($a, $b) => $a > $b);
// With
usort($array, fn($a, $b) => $a <=> $b);
?>
Using an empty file as ZipArchive is deprecated. Libzip 1.6.0 does not accept empty files as valid zip archives any longer. The existing workaround will be removed in the next version.
The procedural API of Zip is deprecated. Use ZipArchive instead. Iteration over all entries can be accomplished using ZipArchive::statIndex() and a for loop:
<?php
// iterate using the procedural API
assert(is_resource($zip));
while ($entry = zip_read($zip)) {
echo zip_entry_name($entry);
}
// iterate using the object-oriented API
assert($zip instanceof ZipArchive);
for ($i = 0; $entry = $zip->statIndex($i); $i++) {
echo $entry['name'];
}
?>
ReflectionFunction::isDisabled() is deprecated, as it is no longer
possible to create a ReflectionFunction for a disabled function. This
method now always returns false
.
ReflectionParameter::getClass(), ReflectionParameter::isArray(), and ReflectionParameter::isCallable() are deprecated. ReflectionParameter::getType() and the ReflectionType APIs should be used instead.