Deprecated Features
PHP Core
Implementing Serializable without __serialize[] and __unserialize[]
Either only the new methods should be implemented, if no support for PHP prior to version 7.4 is provided, or both should be implemented.
Passing null
to non-nullable parameters of built-in functions
Scalar types for built-in functions are nullable by default, this behaviour is deprecated to align with the behaviour of user-defined functions, where scalar types need to be marked as nullable explicitly.
Implicit incompatible float to int conversions
The implicit conversion of float to int which leads to a loss in precision is now deprecated. This affects array keys, int type declarations in coercive mode, and operators working on ints.
Calling a static element on a trait
Calling a static method, or accessing a static property directly on a trait is deprecated. Static methods and properties should only be accessed on a class using the trait.
Returning a non-array from __sleep[]
Returning a value which is not an array from __sleep[] now generates a diagnostic.
Returning by reference from a void function
Such a function is contradictory, and already emits the following E_NOTICE
when called: Only variable references should be returned by reference
.
Autovivification from false
Autovivification is the process of creating a new array when appending to a value. Autovivification is prohibited from scalar values, false
however was an exception. This is now deprecated.
Note:
Autovivification from
null
and undefined values is still allowed:
ctype
Verifying non-string arguments
Passing a non-string argument is deprecated. In the future, the argument will be interpreted as a string instead of an ASCII codepoint. Depending on the intended behavior, the argument should either be casted to string or an explicit call to chr[] should be made. All ctype_*[]
functions are affected.
Filter
The FILTER_SANITIZE_STRING
and FILTER_SANITIZE_STRIPPED
filters are deprecated.
The filter.default INI directive is deprecated.
IMAP
The NIL
constant has been deprecated. Use 0
instead.
Intl
Calling IntlCalendar::roll[] with a bool argument is deprecated. Use 1
and -1
instead of true
and false
respectively.
MySQLi
The mysqli_driver::$driver_version property has been deprecated. It was meaningless and outdated, use PHP_VERSION_ID
instead.
Calling mysqli::get_client_info[] or mysqli_get_client_info[] with the mysqli
argument has been deprecated. Call
mysqli_get_client_info[] without any arguments to obtain the version information of the client library.
The mysqli::init[] method has been deprecated. Replace calls to parent::init[] with parent::__construct[].
PDO
The PDO::FETCH_SERIALIZE
fetch mode has been deprecated.
PgSQL
Not passing the connection argument to all pgsql_*[]
functions has been deprecated.
Deprecated Features
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:
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:Calling get_defined_functions[] with
exclude_disabled
explicitly set tofalse
is deprecated and no longer has an effect. get_defined_functions[] will never include disabled functions.
Enchant
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
andENCHANT_ISPELL
constants 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_STR
now 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
orfalse
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.
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 ZipArchive instead. Iteration over all entries can be accomplished using ZipArchive::statIndex[] and a for loop:
Reflection
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.
Deprecated Features
PHP Core
Nested ternary operators without explicit parentheses
Nested ternary operations must explicitly use parentheses to dictate the order of the operations. Previously, when used without parentheses, the left-associativity would not result in the expected behaviour in most cases.
Parentheses are not required when nesting into the middle operand, as this is always unambiguous and not affected by associativity:
Array and string offset access using curly braces
The array and
string offset access syntax using curly braces is deprecated. Use $var[$idx]
instead of $var{$idx}
.
[real] cast and is_real[] function
The [real]
cast is deprecated, use [float]
instead.
The is_real[] function is also deprecated, use is_float[] instead.
Unbinding $this
when $this
is used
Unbinding $this
of a non-static closure that uses $this
is deprecated.
parent
keyword without parent class
Using parent
inside a class without a parent is deprecated, and will throw a
compile-time error in the future. Currently an error will only be generated if/when the parent is accessed at run-time.
allow_url_include INI option
The allow_url_include ini directive is deprecated. Enabling it will generate a deprecation notice at startup.
Invalid characters in base conversion functions
Passing invalid characters to base_convert[], bindec[], octdec[] and hexdec[] will now generate a deprecation notice. The result will still be computed as if the invalid characters did not exist. Leading and trailing whitespace, as well as prefixes of type 0x [depending on base] continue to be allowed.
hebrevc[] function
The hebrevc[] function is deprecated. It can be replaced with nl2br[hebrev[$str]]
or, preferably, the use of Unicode RTL support.
Implode with historical parameter order
Passing parameters to implode[] in reverse order
is deprecated, use implode[$glue, $parts]
instead of implode[$parts, $glue]
.
COM
Importing type libraries with case-insensitive constant registering has been deprecated.
Filter
FILTER_SANITIZE_MAGIC_QUOTES
is deprecated, use FILTER_SANITIZE_ADD_SLASHES
instead.
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.
Reflection
Calls to ReflectionType::__toString[] now generate a deprecation notice. This method has been deprecated in favor of ReflectionNamedType::getName[] in the documentation since PHP 7.1, but did not throw a deprecation notice for technical reasons.
The export[]
methods on all Reflection classes are deprecated. Construct a Reflection object and convert it to string instead:
Socket
The AI_IDN_ALLOW_UNASSIGNED
and
AI_IDN_USE_STD3_ASCII_RULES
flags for socket_addrinfo_lookup[] are deprecated, due to an upstream deprecation in glibc.
Deprecated Features
PHP Core
Case-Insensitive Constants
The declaration of case-insensitive constants has been deprecated. Passing true
as the third argument to define[] will now generate a deprecation warning. The use of case-insensitive constants with a case that differs from the declaration is also deprecated.
Namespaced assert[]
Declaring a function
called assert[]
inside a namespace is deprecated. The assert[] function is subject to special handling by the engine, which may lead to inconsistent behavior when defining a namespaced function with the same name.
Searching Strings for non-string Needle
Passing a non-string needle to string search functions is deprecated. In the future the needle will be interpreted as a string instead of an ASCII codepoint. Depending on the intended behavior, you should either explicitly cast the needle to string or perform an explicit call to chr[]. The following functions are affected:
- strpos[]
- strrpos[]
- stripos[]
- strripos[]
- strstr[]
- strchr[]
- strrchr[]
- stristr[]
Data Filtering
The explicit usage of the constants
FILTER_FLAG_SCHEME_REQUIRED
and FILTER_FLAG_HOST_REQUIRED
is now deprecated; both are implied for FILTER_VALIDATE_URL
anyway.
Internationalization Functions
Usage of the Normalizer::NONE
form throws a deprecation warning, if PHP is linked with ICU ≥ 56.
Multibyte String
The following undocumented mbereg_*[]
aliases have been deprecated. Use the corresponding
mb_ereg_*[]
variants instead.
- mbregex_encoding[]
- mbereg[]
- mberegi[]
- mbereg_replace[]
- mberegi_replace[]
- mbsplit[]
- mbereg_match[]
- mbereg_search[]
- mbereg_search_pos[]
- mbereg_search_regs[]
- mbereg_search_init[]
- mbereg_search_getregs[]
- mbereg_search_getpos[]
- mbereg_search_setpos[]
ODBC and DB2 Functions [PDO_ODBC]
The pdo_odbc.db2_instance_name ini setting has been formally deprecated. It is deprecated in the documentation as of PHP 5.1.1.
Deprecated features in PHP 7.2.x
Unquoted strings
Unquoted strings that are non-existent global constants are taken to be strings of themselves. This behaviour used to emit an E_NOTICE
, but will now emit an E_WARNING
. In the next major version of PHP, an Error exception will be thrown instead.