A brief overview of PHP language changes using keep a changelog principles.
The main goal of this project is to build the changes summary of PHP language.
PHP 7.3 became an unsupported branch. The last release was 7.4.33.
PHP 7.3 became an unsupported branch. The last release was 7.3.33.
PHP 7.2 became an unsupported branch. The last release was 7.2.34.
-
Named arguments (RFC)
Usage example:
htmlspecialchars($string, double_encode: false);
-
Attributes: a way to add structured metadata with PHP's native syntax (RFC, documentation)
-
Constructor property promotion: less boilerplate code to define and initialize properties (RFC, documentation)
-
Union types: native type declarations that are validated at runtime instead of PHPDoc annotations (RFC, documentation)
-
Match expression (RFC, documentation)
-
Nullsafe operator
?->
(RFC)
- Saner string to number comparisons (RFC)
- Consistent type errors for internal functions: most of the internal functions now throw an Error exception if the validation of the parameters fails (RFC)
- Stricter type checks for arithmetic/bitwise operators
- Fatal error for incompatible method signatures (RFC)
- If a parameter with a default value is followed by a required parameter, the default value has no effect.
- 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.
PHP 7.1 became an unsupported branch. The last release was 7.1.33.
-
Added FFI: a new extension, which provides a simple way to call native functions, access native variables, and create/access data structures defined in C libraries. (documentation)
-
Typed properties
-
Arrow functions (documentation)
-
Null coalescing assignment operator
Usage example:
$array['key'] ??= computeDefault();
-
Unpacking inside arrays
-
Numeric literal separator (value example:
1_000_000
) -
Weak references (documentation)
-
Added the
mb_str_split()
function, which provides the same functionality as str_split(), but operating on code points rather than bytes.
- Trying to use values of type
null
,bool
,int
,float
or resource as an array (such as$null["key"]
) will now generate a notice. fn
is now a reserved keyword. In particular, it can no longer be used as a function or class name. It can still be used as a method or class constant name.
-
Curly brace syntax for accessing array elements and string offsets is deprecated (RFC)
-
(real)
cast andis_real()
function are deprecated.Use
(float)
andis_float()
instead. -
The
money_format()
function is deprecated. It can be replaced by the intlNumberFormatter
functionality. -
Nested ternary operations must explicitly use parentheses to dictate the order of the operations.
- As of PHP 7.4.11, the names of incoming cookies are no longer url-decoded for security reasons.
PHP 7.0 became an unsupported branch. The last release was 7.0.33.
PHP 5.6 became an unsupported branch. The last release was 5.6.40.
- Added support for references in
list()
and array destructuring (RFC). - Trailing commas in function and method calls are now allowed.
- Added support for the SameSite cookie directive.
- Added
array_key_first()
&array_key_last()
functions. - Added
is_countable()
function. - Added
hrtime()
function to get high resolution time.
- Implemented flexible heredoc and nowdoc syntax (RFC).
- The Multibyte String data tables have been updated for Unicode 11.
- Performance of the Multibyte String extension has been significantly improved across the board.
- The PCRE extension has been upgraded to PCRE2, which may cause minor behavioral changes (RFC).
- If an SPL autoloader throws an exception, following autoloaders will not be executed. Previously all autoloaders were executed and exceptions were chained.
- The cyclic GC has been enhanced, which may result in considerable performance improvements.
- The declaration and use of case-insensitive constants has been deprecated.
- Declaring a function called
assert()
inside a namespace is deprecated.
mysqli
&pdo_mysql
extensions: prepared statements now properly report the fractional seconds forDATETIME
,TIME
andTIMESTAMP
columns with decimals specifier (e.g.TIMESTAMP(6)
when using microseconds). Formerly, the fractional seconds part was simply omitted from the returned values.
- As of PHP 7.3.23, the names of incoming cookies are no longer url-decoded for security reasons.
- A new type,
object
, has been introduced that can be used for (contravariant) parameter typing and (covariant) return typing of any objects.
- Parameter types from overridden methods and from interface implementations may now be omitted.
- Abstract methods can now be overridden when an abstract class extends another abstract class
- Shared extensions no longer require their file extension (.so for Unix or .dll for Windows) to be specified. This is enabled in the php.ini file, as well as in the
dl()
function. - The MCrypt extension has now been moved out of the core to PECL. Given the mcrypt library has not seen any updates since 2007, its usage is highly discouraged. Instead, either the OpenSSL or Sodium extension should be used.
- 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.
- The
__autoload()
method has been deprecated because it is inferior tospl_autoload_register()
- Given the security issues of
create_function()
function, this dated function has been deprecated. The preferred alternative is to use anonymous functions. each()
function is far slower at iteration than a normal foreach, and causes implementation issues for some language changes. It has therefore been deprecated.
- The
sql.safe_mode
ini setting has now been removed.
- A
void
return type has been introduced. Functions declared with void as their return type must either omit their return statement altogether, or use an empty return statement. NULL is not a valid return value for a void function. - Support for specifying the visibility of class constants has been added.
- A new pseudo-type (similar to callable) called iterable has been introduced. It may be used in parameter and return types, where it accepts either arrays or objects that implement the Traversable interface.
- Multiple exceptions per catch block may now be specified using the pipe character (
|
). This is useful for when different exceptions from different class hierarchies are handled the same. - A new function called
pcntl_async_signals()
has been introduced to enable asynchronous signal handling without using ticks. - Adding new
is_iterable
function.
- Type declarations for parameters and return values can now be marked as nullable by prefixing the type name with a question mark. This signifies that as well as the specified type, NULL can be passed as an argument, or returned as a value, respectively.
- The shorthand array syntax (
[]
) may now be used to destructure arrays for assignments (including within foreach), as an alternative to the existinglist()
syntax, which is still supported. - Variables bound to a closure via the use construct cannot use the same name as any superglobals,
$this
, or any parameter. - You can now specify keys in
list()
, or its new shorthand[]
syntax. This enables destructuring of arrays with non-integer or non-sequential keys. - Support for negative string offsets has been added to the string manipulation functions accepting offsets, as well as to string indexing with
[]
or{}
. In such cases, a negative offset is interpreted as being an offset from the end of the string. - Previously, a warning would be emitted for invoking user-defined functions with too few arguments. Now, this warning has been promoted to an Error exception. This change only applies to user-defined functions, not internal functions.
void
anditerable
cannot be used to name classes, interfaces, or traits.- Applying the empty index operator to a string (e.g.
$str[] = $x
) throws a fatal error instead of converting silently to array. - Session IDs will no longer be hashed upon generation. With this change brings about the removal of the following four ini settings:
session.entropy_file
,session.entropy_length
,session.hash_function
,session.hash_bits_per_character
.
DateTime
andDateTimeImmutable
now properly incorporate microseconds when constructed from the current time, either explicitly or with a relative string (e.g. "first day of next month"). This means that naive comparisons of two newly created instances will now more likely return FALSE instead of TRUE.
PHP 5.5 became an unsupported branch. The last release was 5.5.37.
- PHP 7 adds support for return type declarations
- The null coalescing operator (
??
) has been added as syntactic sugar for the common case of needing to use a ternary in conjunction withisset()
- The spaceship operator is used for comparing two expressions. It returns -1, 0 or 1 when
$a
is respectively less than, equal to, or greater than$b
. - Support for anonymous classes has been added via
new class
.
- Array constants can now be defined with
define()
. In PHP 5.6, they could only be defined withconst
. - Filtered
unserialize()
list()
can no longer unpack string variables.str_split()
should be used instead.dirname()
now optionally takes a second parameter, depth, to get the name of the directory depth levels up from the current directory.setlocale()
function no longer accepts category passed as string.LC_*
constants must be used instead.- FPM SAPI module: In PHP 5, a listen directive with only a port number would listen on all interfaces, but only on IPv4. PHP 7 will now accept requests made via both IPv4 and IPv6.
- PHP 4 style constructors (methods that have the same name as the class they are defined in) are deprecated, and will be removed in the future.
- Static calls to methods that are not declared static are deprecated, and may be removed in the future.
- The
salt
option for thepassword_hash()
function has been deprecated to prevent developers from generating their own (usually insecure) salts. The function itself generates a cryptographically secure salt when no salt is provided by the developer - therefore custom salt generation should not be needed.
- Removed extensions:
ereg
,mssql
,mysql
. - Removed SAPIs:
apache
,apache_hooks
,apache2filter
, etc - Removal of date.timezone Warning
Previously, a warning was emitted if the date.timezone INI setting had not been set prior to using any date- or time-based functions. Now, this warning has been removed (with date.timezone still defaulting to UTC).
PHP 5.4 became an unsupported branch. The last release was 5.4.45.
PHP 5.3 became an unsupported branch. The last release was 5.3.29.
PHP 5.2 became an unsupported branch. The last release was 5.2.17.
The end of life for PHP 4.4 also marks the end of life for PHP 4 as a whole.
PHP 5.1 became an unsupported branch. The last release was 5.1.6.
PHP 5.0 became an unsupported branch. The last release was 5.0.5.
Feature related sources:
- http://php.net/manual/en/appendices.php
- https://www.php.net/releases/8.2/en.php
- https://www.php.net/releases/8.1/en.php
- https://www.php.net/releases/8.0/en.php
- https://www.php.net/ChangeLog-8.php
- http://php.net/ChangeLog-7.php
- http://php.net/ChangeLog-5.php
Date related sources: