PHP 8.4 introduces several exciting features and improvements while deprecating or removing outdated functionality. Here’s a comprehensive overview of what’s new and what’s changed.
🚀 Key Features and Improvements in PHP 8.4
1. Property Hooks
Property hooks allow custom behavior when accessing, modifying, or unsetting class properties. This eliminates the need for boilerplate getter and setter methods.
Example:
2. Asymmetric Visibility
You can now define different visibility levels for property getters and setters. For instance, a property can have a public
getter but a private
setter.
Example:
3. MyClass()->method()
Without Parentheses
PHP 8.4 simplifies syntax by allowing methods without parentheses if they take no parameters.
Example:
4. HTML5 Support
PHP 8.4 improves compatibility with modern web development by enhancing functions like htmlspecialchars()
and htmlentities()
for better handling of HTML5 attributes and entities.
Example:
5. JIT Changes
The Just-In-Time (JIT) compiler has been refined for better performance in real-world scenarios, particularly for computation-heavy scripts and long-running processes. You can control JIT via opcache.jit
.
6. Lazy Objects
Lazy objects are instantiated only when accessed, improving memory usage and performance in applications with complex objects.
Example:
This helps in cases where creating the object upfront would be too costly, and its initialization is deferred until needed.
7. Exit and Die as Functions
The exit
and die
constructs are now proper functions, enabling their use in variable function calls or callbacks.
Example:
8. Multibyte Trim Functions
With mb_trim()
, PHP 8.4 introduces trimming functions that handle multibyte characters, making string manipulation more reliable for non-ASCII languages.
Example:
This feature is crucial for working with languages like Japanese, Chinese, and Korean, where regular trimming functions may not work correctly.
📉 Deprecations in PHP 8.4
PHP 8.4 deprecates several outdated features, encouraging developers to adopt modern practices. Below is the complete list of deprecations and removals.
1. DOMDocument and DOMEntity Properties
The soft-deprecated properties in DOMDocument
and DOMEntity
are formally deprecated.
2. E_STRICT Constant
The E_STRICT
constant has been deprecated since its functionality is already included in other error levels.
3. strtok()
The strtok()
function is deprecated due to its limited usage compared to modern alternatives like explode()
or preg_split()
.
4. User Output Handlers
Two key deprecations include:
- Returning non-string values from user-defined output handlers.
- Producing output directly within an output handler.
5. file_put_contents()
with Arrays
Passing an array as $data
to file_put_contents()
is no longer supported. Use a string instead.
Example:
6. MySQLi Deprecations
Several MySQLi functions are deprecated, including:
mysqli_ping()
mysqli_refresh()
mysqli_kill()
- Second parameter for
mysqli_store_result()
7. DOMImplementation::getFeature()
The DOMImplementation::getFeature()
method has been removed.
8. Deprecation of Hashing Functions
The following functions are deprecated due to security and performance concerns:
md5()
sha1()
md5_file()
sha1_file()
9. uniqid()
and lcg_value()
These functions are deprecated for their inability to generate cryptographically secure or reliable unique values.
10. Other Notable Deprecations
- Session configurations:
session.sid_length
andsession.sid_bits_per_character
. - Legacy constants:
SUNFUNCS_RET_STRING
,SUNFUNCS_RET_DOUBLE
,SUNFUNCS_RET_TIMESTAMP
. - SOAP_FUNCTIONS_ALL constant for
SoapServer::addFunction()
. - Deprecation of proprietary CSV escaping mechanisms.
Conclusion
PHP 8.4 builds upon its strong foundation with powerful features like property hooks, lazy objects, and asymmetric visibility, while addressing outdated and insecure functionalities. It strikes a balance between innovation and modernization, making it a must-consider upgrade for developers.
Are you ready to adopt PHP 8.4? Let us know your thoughts!
Subscribe to my Newsletter
Get the latest updates right to your inbox. Subscribe now!
We respect your privacy. Unsubscribe at any time.