PHP 8.2 is planned to release on November 24, 2022, with the most recent stable version being PHP 8.1.5. PHP 8.2 is built to renew and bring ease to development and fix bugs found in the older PHP versions.
Knowing what to anticipate from PHP 8.2 will help you prepare for the release. By learning about the new features and the older ones being deprecated, you’ll better understand how the upgrade will affect your site’s development.
This article details what’s new in PHP 8.2 — from its new features and improvements to deprecations and minor changes. Keep reading to learn more about this major release.
What’s New In PHP 8.2?
PHP brings a handful of fundamental features with each release. This section covers the new features coming in PHP 8.2. Also, using the latest PHP version is suggested to maximize your site’s security & get syntax and execution upgrades:
Readonly classes
PHP 8.1 gave us readonly properties for classes, which was an incredible jump for many projects. However, it still required a little gap for plugging into classes.
PHP 8.1 allowed you to make each typed property in a class readonly but required a lot of typing, which was a nightmare for developers. So instead, in PHP 8.2, you can mark an entire course as readonly.
readonly class MyClass { public int $myProp; public string $myOtherProp; public __construct(string $myOtherProp, int $myProp) { $this->myProp = $myProp; $this->myOtherProp = $myOtherProp; } }
Here we have a class defined as readonly. We have 2 properties of the class, and both of them are inherently readonly. Although the readonly rules from PHP 8.1 still apply, you can initialize the property once; after that, it is set.
$myObj = new MyClass(‘Cal was here’,42); Once they are initialized, they get immutable. $myObj->myProp = ‘Cal is no longer here’; // Fatal Error: Uncaught Error: Cannot modify readonly property MyClass::myProp
One other behavior of the readonly class is that it does not let you add properties dynamically to the lesson. Remember that if you stamp a class as readonly, it cannot be overridden at a certain point.
New memory_reset_peak_usage Function
PHP 8.2 will add a new function called memory_reset_peak_usage. This function will let you reset the top memory usage returned by the memory_get_peak_usage function.
The memory_reset_peak_usage function will be supportive for cases that include invoking an action multiple times and recording or resetting the peak memory utilization of each cycle.
Null and False Standalone Types
In PHP 8.2, the false return type will be accessible as a standalone sort instead of a union sort whenever an error occurs:
function alwaysFalse(): false { return false; }
The same is true for the invalid type. For example, as a standalone type, NullPost::getAuthor() will be able to return it as null, unlike before. However, null, true, and false may be considered valid types on their own.
Stop Wasting Time on Servers
Cloudways handle server management for you so you can focus on creating great apps and keeping your clients happy.
Deprecate Partially Supported Callables
The partially supported callables will be deprecated with PHP 8.2. There are different ways to create a callable in PHP. You can call it with or without parameters with the $callable() syntax, the user_call_func(/a_array), or a function with a callback.
Passing these callables to the is_callable() function or using them with the callable parameter sorts won’t create the deprecation message. To understand the deprecation notice, developers can instead change over the parent, self, and inactive keywords in callable code to their particular class names utilizing the::class strategy.
New /n Modifier
PHP 8.2 will incorporate the /n (no capture) modifier to the preg_* work family. When utilized, any groups with()meta-characters won’t capture anything separated from the named captured group. So, the result is the same as checking each group as non-capturing.
This change is because the modifier simplifies complex customary expressions for different groups. Instead of showcasing each group as non-capturing, developers can check all groups as non-capturing. At this point, developers can select and name specific bunches captured.
Deprecate ${} String Interpolation
There are different ways to embed variables in strings with PHP. However, PHP 8.2 will deprecate two methods.
"Hello, ${world}!"; Using ${} in strings is deprecated "Hello, ${(world)}!"; Using ${} (variable variables) in strings is deprecated
However, these deprecations wouldn’t be a significant issue for developers as the two most well-known string addition methods will still work.
Other Minor Improvements
Along with new features, some existing features in the older PHP versions will be tweaked and improved in PHP 8.2, like
Random Extension Improvement
The pioneer PHP random number generator is still used within the base code. It’s never been great and completely useless for cryptographic uses.
PHP 7 introduced new functions like random_int() and random_bytes(). They went a long way to fix the issues, but under the hood, these functions are interfaces to the local OS’s random number generator.
It was a great solution at the time but is very slow. But, with PHP 8.2, we will get an extensible object-oriented interface rather than a completely modern Random number generator built into PHP.
Additional RFCs in PHP 8.2
PHP 8.2 also comes in with many new functions and minor changes: PHP 8.2 RFCs (Random Extension Improvement) is prepared to fix the issues found with a new curl_upkeep function to its Curl extension. It calls the curl_easy_upkeep() function in libcurl.
New ini_parse_quantity work: PHP INI directives acknowledge data sizes with a multiplier suffix. For instance, you’ll be able to compose 25 Megabytes as 25M or 42 Gigabytes as just 42G. These postfixes are common in PHP INI files but are unprecedented somewhere else. This new function parses the PHP INI values and returns their data size in bytes.
New memory_reset_peak_usage work: This function resets the top memory utilization returned by the memory_get_peak_usage function. It is helpful when you’re running the same action multiple times and need to record each run’s peak memory utilization.
Nothing as Easy as Deploying PHP Apps on Cloud
With Cloudways, you can have your PHP apps up and running on managed cloud servers in just a few minutes.
Which Features Are Removed in PHP 8.2?
PHP 8.2 will introduce many new features but has also removed the support of MYSQLi with libmyql:
MySQLi Will No Longer Be Compiled With libmysql
Starting with PHP 8.2, MySQLi with libmysql won’t be supported, and the attempt to do so will result in a configuration error. In the past, PHP has supported two database libraries for interfacing that are MySQL databases: mysqlnd and libmysql.
As of PHP 5.4, MySQL has been the default library, and you can compile MySQLi through extensions. This won’t likely cause any critical issues for developers.
However, the two of the most significant features supported by libmysql that aren’t accessible with MySQLnd are supported, i.e., authentication and automatic reconnecting through LDAP and SASL.
How to Upgrade to the Latest PHP Version on Cloudways
You can easily upgrade your current PHP version to the latest version on Cloudways by following the steps below:
- Login to the Cloudways Platform.
- Select your server.
- You’ll be redirected to the Server Management page.
- Click Settings & Packages > Packages.
Select PHP 8.1 from the drop-down menu
Click Save.
That’s how easily you can upgrade your PHP version on Cloudways.
Note: PHP 8.2 hasn’t been officially released yet. Once PHP 8.2 is released and made available on the Cloudways platform, you can upgrade to PHP 8.2 by following the above steps.
Keep Your PHP Version Up to Date
PHP 8.2 builds upon the massive improvements needed in PHP 8.0 and PHP 8.1. PHP 8.2 features are quite anticipated among the developers, including the new standalone type, readonly properties, and various execution improvements.
As a developer, it’s fundamental to test your code against up-and-coming updates and versions of PHP. Once 8.2 is officially released, Cloudways will start working to make PHP 8.2 available on its platform as soon as possible.
Q. What is the difference between PHP 8.1 and 8.2?
A: The readonly feature for class properties was a new feature in PHP 8.1. But, PHP 8.2 will now let you declare not just the class properties but the entire class as readonly.
Q. What will be deprecated in PHP 8.2?
A: PHP 8.2 will deprecate the dynamic properties such as partially supported callables and String Interpolation.
Q. Why should I upgrade to PHP 8.2?
A: PHP 8.2 will use the parameters to access private information from the stack, making them more secure. It is always recommended to upgrade to the latest PHP versions to speed up your sites and strengthen their security. We recommend upgrading to PHP 8.2 to use the latest features and get rid of the bugs reported in the earlier versions.
Q. Is PHP 8.2 better?
A: The usage of PHP versions totally depends upon the user’s requirements. However, it is always recommended to keep your version upgraded to keep your website secure.
Q. What is the latest version of PHP 8?
A: PHP’s latest version is 8.1, released in November 2021. However, PHP 8.2 is scheduled to release on November 24, 2022.
Customer Review at
“Cloudways hosting has one of the best customer service and hosting speed”
Sanjit C [Website Developer]
Shahzeb Ahmed
Shahzeb is a Digital Marketer with a Software Engineering background, works as a Community Manager — PHP Community at Cloudways. He is growth ambitious and aims to learn & share information about PHP & Laravel Development through practice and experimentation. He loves to travel and explore new ideas whenever he finds time. Get in touch with him at [email protected]