PHP 7.4 may be released in December 2019. This page will be updated regularly.
Preloading
Preloadingrfc
Preloading
(preloading) is an amazing addition to PHP core that can bring some major performance improvements.
In short: If you are using a framework today, its files must be loaded and recompiled on every request. Preloading allows the server to load PHP files in memory on startup and make them permanently available to all subsequent requests.
The increased performance comes at a cost, of course: if the source of the preloaded files changes, the server must be restarted.
Typed properties
rfc
Class variables can be type hints:
class A { public string $name; public Foo $foo; }
Update:To So far, Typed properties have been merged, confirming them for PHP 7.4.
Improved type variance
(Improved type variance)rfc
I have written before Article about the PHP type system, so it's nice to see some improvements coming to the PHP core.
Type differences are a topic worthy of its own blog post;
In short: you will be able to usecovariant
return types
class ParentType {} class ChildType extends ParentType {} class A { public function covariantReturnTypes(): ParentType { /* … */ } } class B extends A { public function covariantReturnTypes(): ChildType { /* … */ } }
andcontravariant
Parameters.
class A { public function contraVariantArguments(ChildType $type) { /* … */ } } class B extends A { public function contraVariantArguments(ParentType $type) { /* … */ } }
Update: The RFC is currently in the voting stage, but it looks like it will pass without any issues.
Foreign Function Interface
(External Function Interface)rfc
Foreign Function Interface, referred to as FFI, allows calling C code from userland. This means that PHP extensions can be written in pure PHP.
It’s worth noting that this is a complex topic. You still need C knowledge to use this feature correctly.
Null
Merge assignment operatorrfc
Not this way:
$data['date'] = $data['date'] ?? new DateTime();
You can do this:
$data['date'] ??= new DateTime();
Update: This feature is now merged into PHP 7.4.
Custom object serializationrfc
This RFC adds two new magic methods:__serialize
and__unserialize
. The differences between these methods and the__sleep
and__wakeup
methods are discussed in the RFC.
Update: RFC passed. This feature will be added in PHP 7.4.
No more narrow margins
rfc
Technically, this is not an update related to PHP 7.4 , but it's certainly worth mentioning. The voting rules for RFCs have changed: they always require a 2/3 majority to pass.
Reflection for references
rfc
Libraries like Symfony’s var dumper heavily rely on Reflection API to dump variables reliably. Previously, there was no proper reflection support for references, causing these libraries to rely on hacks to detect references.
PHP 7.4 added theReflectionReference
class to solve this problem.
Update: RFC passed, changes confirmed for PHP 7.4.
Addmb_str_split
rfc
This function provides the same functionality as str_split, but on multi-byte characters On skewers.
Always enabledext-hash
rfc
As the title says, this extension is now included in all PHP installations is permanently available.
Not enabled by defaultPEAR
Since PEAR is no longer actively maintained, the core team decided to remove its default installation with PHP 7.4.
Password Hashing(Hashing
) Registryrfc
Internal Change Hash Library way to make it easier for users to use them.
DEPRECATEDext/wwdx
rfc
This data exchange format has never been standardized However, its extension is now deprecated.
Upgrading Backward-Incompatible Changes
When upgrading a PHP version, you should always review theFull Upgrade Documentation.
Here are some of the backwards-incompatible changes highlighted:
•parent::
Referencing in a class without a parent will generate a compile-time error instead Runtime error.
• Calling var_dump on aDateTime
ordatetimevariable
instance will no longer leave accessible properties on the object.
•openssl_random_pseudo_bytes
Will throw an exception in error conditions.
• Attempts to serialize aPDO
orPDOStatement
instance will generate an exception instead of aPDOException
.
• Callingget_object_vars()
on anArrayObject
instance will return the properties of theArrayObject
itself, not the values of the wrapped array or object . Note that (array) casts are not affected.
Translated from: https://stitcher.io/blog/new-in-php-74#reflection-for-references-rfc
Related recommendations:
《The difference in security between PHP7 and PHP5 (example)》
《Changes brought about by the Abstract Syntax Tree (AST) of PHP7》
《The execution principle of PHP7 language (PHP7 source code analysis)》