News

PHP 8.3 is Now Available at ChemiCloud

February 13, 2024

We are happy to announce that PHP 8.3 is now available at ChemiCloud for all environments.

PHP continues evolving with each new version, bringing enhancements, optimizations, and new features. PHP 8.3 is no exception, offering developers many improvements to streamline development, enhance performance, and bolster security.

In this article, we'll delve into the main features and benefits of this new version, highlighting why you should consider upgrading to this latest version.

PHP 8.3 brings several performance optimizations aimed at improving code execution efficiency. One of the significant improvements is the handling of attribute lookups, which has been enhanced to reduce overhead when working with attributes in classes and methods.

Furthermore, optimizations in the engine's internal data structures contribute to overall performance gains, ensuring that PHP applications run more smoothly and efficiently than ever before.

Major Improvements and New Features

Typed Class Constants: Since PHP 7.4, developers have had the capability to specify types for class properties, a feature that enhanced the language's type system significantly. However, this type specification did not extend to constants, despite various enhancements to PHP's typing system over time. With the arrival of PHP 8.3, this limitation has been addressed. Now, class constants, as well as those within interfaces, traits, and enums, can be declared with specific types. This advancement reduces the chances of developers deviating from the original intent behind a constant's declaration, ensuring greater adherence to predefined data types and enhancing code reliability.

A New json_validate() Function: This function evaluates a string to determine if it is a valid JSON format, returning a boolean result: true if the string is valid JSON, and false otherwise. Before the introduction of PHP 8.3, the primary method to check for a valid JSON string involved using json_decode and then checking for errors, a process that could be resource-intensive. The json_validate function offers an improvement by leveraging the same JSON parser used by PHP, but it operates more efficiently. Unlike json_decode, json_validate merely examines the string for validity without actually constructing a decoded object, thereby using less memory and processing power.

Dynamic Fetching of Class Constants and Enum Members: PHP 8.3 simplifies the process of accessing class constants and enum members using variable names. The previously cumbersome approach of employing the constant() function has been superseded by a more intuitive syntax. This improvement significantly enhances the readability of the code, making it easier for developers to work with dynamic constant and enum member names.

New getBytesFromString() Method: Generating random strings from a specific set of characters has become much more straightforward with the introduction of the getBytesFromString() method in the Random extension of PHP 8.3. This method is straightforward to use: you provide it with a string containing the characters you wish to include in your random string and specify the desired length of the output. The method then randomly selects bytes from the provided string until it constructs a string of the length you specified.

New getFloat() and nextFloat() Methods: Building upon the capabilities of the Random extension, PHP 8.3 introduces two novel methods, getFloat() and nextFloat(), aimed at generating random floating-point numbers. These additions offer improved precision and give developers greater control in the creation of random float values.

gc_status() Now Returns Additional Information: With this update, it now provides more comprehensive information, including the garbage collector's running status, protection status, buffer size, among other details.

Deprecated Features in PHP 8.3

With each new version of PHP, certain functions and configurations are marked for future removal. These deprecated features, while still operational, are no longer recommended for use and will typically trigger warnings in logs during code execution.

Below is an updated list of deprecations in PHP 8.3, including references for further details:

The U_MULTIPLE_DECIMAL_SEPERATORS constant has been deprecated in favor of  U_MULTIPLE_DECIMAL_SEPARATORS.

The 3MT_RAND_PHP Mt19937 variant is now considered deprecated.

ReflectionClass::getStaticProperties() cannot return null anymore.

Several INI settings, including assert.active, assert.bail, assert.callback, assert.exception, and assert.warning, have been deprecated.

The use of get_class() and get_parent_class() functions without providing any arguments has been deprecated.

unserialize() function's behavior has been modified, with specific error scenarios that used to trigger notices (E_NOTICE) now generating warnings (E_WARNING) instead. This adjustment affects situations like syntax errors and issues with custom __unserialize handlers.

Adapting to Change

For developers, these deprecations serve as a call to modernize codebases. Here are a few strategies to manage these changes:

Audit Your Code: Use static analysis tools to identify deprecated features in your code. Tools like PHPStan or Psalm can help spot usage of deprecated features.

Embrace Modern Practices: Refactor your code to use modern PHP features and coding standards. For example, replace dynamic properties with explicitly declared class properties.

Update Dependencies: Ensure that any third-party libraries or frameworks you use are up to date and compatible with PHP 8.3.

Test Thoroughly: With any changes you make, comprehensive testing is crucial to catch any issues arising from the migration away from deprecated features.

For a complete list of improvements, new features, and deprecations, be sure to review the PHP.net official documentation and changelog.

And now, let’s see how to enable PHP 8.3 on your sites!

How to Switch to PHP 8.3 in cPanel

You can easily update your PHP version to 8.3, from cPanel, using the PHP Selector by following the steps described below:

Step 1) Log into cPanel

Step 2) Navigate to the Software section and click on the Select PHP version option


Step 3) Click on the PHP Version drop-down box and select 8.3 version:


Step 4) Click on the Apply button to save your PHP version change.

That's it! 

Conclusion

PHP 8.3 brings a host of enhancements and new features that promise to improve developer productivity, enhance code quality, and boost application performance. From performance optimizations and type system enhancements to new language features like enums and read-only properties, PHP 8.3 offers something for every developer.

By upgrading to PHP 8.3, developers can take advantage of these improvements and build better, more robust PHP applications.