Deprecated Features
If a parameter with a default value is followed by a required parameter, the default value has no effect. This is deprecated as of PHP 8.0.0 and can generally be resolved by dropping the default value, without a change in functionality:
PHP Core
If a parameter with a default value is followed by a required parameter, the default value has no effect. This is deprecated as of PHP 8.0.0 and can generally be resolved by dropping the default value, without a change in functionality:
php<?php function test($a = [], $b) {} // Before function test($a, $b) {} // After ?>One exception to this rule are parameters of the form
Type $param = null, where the null default makes the type implicitly nullable. This usage remains allowed, but it is recommended to use an explicit nullable type instead:php<?php function test(A $a = null, $b) {} // Still allowed function test(?A $a, $b) {} // Recommended ?>- Calling
get_defined_functions()withexclude_disabledexplicitly set to false is deprecated and no longer has an effect.get_defined_functions()will never include disabled functions.
Enchant
enchant_broker_set_dict_path()andenchant_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; useenchant_dict_add()instead.enchant_dict_is_in_session()is deprecated; useenchant_dict_is_added()instead.enchant_broker_free()andenchant_broker_free_dict()are deprecated; unset the object instead.- The
ENCHANT_MYSPELLandENCHANT_ISPELLconstants are deprecated.
LibXML
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.
PGSQL / PDO PGSQL
- The constant
PGSQL_LIBPQ_VERSION_STRnow has the same value asPGSQL_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:
pg_errormessage()→pg_last_error()pg_numrows()→pg_num_rows()pg_numfields()→pg_num_fields()pg_cmdtuples()→pg_affected_rows()pg_fieldname()→pg_field_name()pg_fieldsize()→pg_field_size()pg_fieldtype()→pg_field_type()pg_fieldnum()→pg_field_num()pg_result()→pg_fetch_result()pg_fieldprtlen()→pg_field_prtlen()pg_fieldisnull()→pg_field_is_null()pg_freeresult()→pg_free_result()pg_getlastoid()→pg_last_oid()pg_locreate()→pg_lo_create()pg_lounlink()→pg_lo_unlink()pg_loopen()→pg_lo_open()pg_loclose()→pg_lo_close()pg_loread()→pg_lo_read()pg_lowrite()→pg_lo_write()pg_loreadall()→pg_lo_read_all()pg_loimport()→pg_lo_import()pg_loexport()→pg_lo_export()pg_setclientencoding()→pg_set_client_encoding()pg_clientencoding()->pg_client_encoding()
Standard Library
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<?php // Replace usort($array, fn($a, $b) => $a > $b); // With usort($array, fn($a, $b) => $a <=> $b); ?>
Zip
- 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
ZipArchiveinstead. Iteration over all entries can be accomplished usingZipArchive::statIndexand a for loop:php<?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']; } ?>
Reflection
ReflectionFunction::isDisabledis deprecated, as it is no longer possible to create aReflectionFunctionfor a disabled function. This method now always returns false.ReflectionParameter::getClass,ReflectionParameter::isArray, andReflectionParameter::isCallableare deprecated.ReflectionParameter::getTypeand theReflectionTypeAPIs should be used instead.