PHP

PHP 8.2 Is Now Available on Cloudways (New Features, Deprecations, and More)

On November 24, 2022, the highly anticipated PHP 8.2 was released to the delight of developers everywhere. With a focus on streamlining development and addressing persistent bugs, this latest version has quickly become the go-to choice for those seeking the ultimate PHP functionality.

Boasting a wealth of new features and improvements, as well as the deprecation of certain outdated features, PHP 8.2 is truly a game-changer. In this informative blog, we will delve into all the exciting updates included in this major release. We’ve got you covered, from new features to deprecations and everything in between.

Moreover, we’ll also cover the steps to upgrading your PHP version to 8.2 on Cloudways. Keep reading to learn more about this major release.

Table of Contents

  1. What’s New In PHP 8.2?
    • Readonly classes
    • New memory_reset_peak_usage Function
    • Null and False Standalone Types
    • Deprecate Partially Supported Callables
    • New /n Modifier
    • Deprecate ${} String Interpolation
    • Other Minor Improvements
    • Random Extension Improvement
    • Additional RFCs in PHP 8.2
  2. Which Features Are Removed in PHP 8.2?
    • MySQLi Will No Longer Be Compiled With libmysql
  3. How to Install PHP 8.2 on Cloudways
  4. How to Upgrade to PHP 8.2 on Cloudways
  5. Keep Your PHP Version Up to Date

What’s New In PHP 8.2?

With every new release, PHP continues to evolve and bring a wealth of essential features to the table. And the latest addition, PHP 8.2, is no exception. Packed with a host of cutting-edge features and improvements, this version will take your website to the next level.

But that’s not all. By upgrading to the latest PHP version, you’re gaining access to new features, enhancing your site’s security, ensuring optimal syntax and execution, and maximizing your online potential. Here are some of the new features that PHP 8.2 has introduced:

Readonly classes

PHP 8.1 introduced readonly properties for classes, revolutionizing developer approaches. However, excessive typing was still a challenge.

PHP 8.2 solves this by allowing entire classes to be marked as readonly, making it easier for developers to use this feature. So, you can upgrade to PHP 8.2 for more efficient use of readonly properties.

  1. readonly class MyClass {
  2. public int $myProp;
  3. public string $myOtherProp;
  4. public __construct(string $myOtherProp, int $myProp)
  5. {
  6. $this->myProp = $myProp;
  7. $this->myOtherProp = $myOtherProp;
  8. }
  9. }

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.

  1. $myObj = new MyClass(‘Cal was here’,42);
  2. Once they are initialized, they get immutable.
  3. $myObj->myProp = ‘Cal is no longer here’;
  4. // Fatal Error: Uncaught Error: Cannot modify readonly property MyClass::myProp

The readonly class also prohibits dynamic property addition, ensuring unwavering stability. Remember that once a class is designated as readonly, it cannot be overridden at a certain point.”

New memory_reset_peak_usage Function

PHP 8.2 has brought a new function, memory_reset_peak_usage, which resets the highest memory usage recorded by memory_get_peak_usage. This function is ideal for monitoring memory utilization in multiple-cycle operations.

Null and False Standalone Types

In PHP 8.2, the false return type is accessible as a standalone sort instead of a union sort whenever an error occurs:

  1. function alwaysFalse(): false
  2. {
  3. return false;
  4. }

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 handles server management for you to help you focus on creating great apps and keeping your clients happy.

Start Free

Deprecate Partially Supported Callables

PHP 8.2 has deprecated the partially supported callables. Callables can be created using the $callable() syntax, the user_call_func(), 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 has also incorporated 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 has deprecated 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, PHP 8.2 has also tweaked some existing features in the older PHP versions, including:

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 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 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 issues 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 can 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.

Start Free

Which Features Are Removed in PHP 8.2?

PHP 8.2 has introduced 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.

Avatar

Shakeel Shahid

About Author

Leave a comment

Your email address will not be published. Required fields are marked *

You may also like

PHP

PHP 8.2.0 Release Rescheduled to December 8

The upcoming major PHP version, PHP 8.2.0, was scheduled to be released as on November 24 this year. Sergey Panteleev, one
PHP

All PHP 7.x versions are now EOL

PHP 7.4, the last version of PHP 7.x series, reached its End-of-Life date today. This essentially means that there will