Introducing The Latest Version Of PHP 8.x

PHP 8.x was released on December 23, 2020 and RunCloud has been working hard to ensure compatibility with its servers. Several weeks later, today, RunCloud is ready to introduce to its users that PHP 8.x which is now available to all accounts located in the web application settings, existing and new. While we highly encourage you keep your PHP version up to date, we do not yet recommend you upgrade to PHP 8.x on your live production servers, especially if you are using WordPress. If you are creating a new web app without WordPress, you may freely give PHP 8.x a try.

There are still many WordPress plugins that are not yet compatible with PHP 8.x and will cause your server or website to error. While PHP 8.x does have good backwards-compatibility with PHP 7.x, we do recommend slowly updating your web applications over time. Currently, RunCloud Support can only offer technical support for errors and bugs that are directly related to the RunCloud dashboard and your web application. If you still choose to update your RunCloud’s PHP version to 8.x, here are some of the latest fixes, bugs, and new features, as well as features that may have been removed.

PHP 8.0.1 is now available with more bug fixes and updates in RunCloud

RunCloud always runs after new updates of PHP and always has been forward to embrace all the most recent updates of PHP. Recently, PHP has officially released the most updated version, 8.0.1 on the 7th January of 2021. So we always look forward to providing you with the most details of PHP, while you have the choice to upgrade or continue with your current version of PHP 7.x. We always recommend the latest version of PHP 7.x to you, as the latest versions are the fastest and most secure.

There is no doubt, PHP is one of the most popular and dominant languages on the Internet. And we need to learn and cope up with the new features to get most out of this language. Lets get started on a review of the latest features.

What’s new in Version 8.0?

PHP Version 8.0 has come up with some great new features like the following:

  • Named Parameters: PHP 8.0 allows named parameters during function or method calls in addition to traditional positional parameters, which helps a lot for new and experienced programmers. This will certainly make the function or method parameter names part of the public API. The non-standardized DocBlock @no-named-arguments expresses that the library does not provide backwards-compatibility for named parameters.
  • Attributes: In PHP 8.0,  Attributes allows declaring meta-data for functions, classes, properties, and parameters. Attributes map to PHP class names (declared with an Attribute itself), and they can be fetched programmatically with PHP Reflection API, which is a great feature of PHP 8.0.
  • Constructor Properties:  In the constructor, PHP 8.0 enables declaring the visibility (public, private, or protected) and type. Those properties will be registered as class properties with the same visibility and type they are declared in the constructor.This backwards-incompatible feature can help reduce boilerplate code when declaring value-object classes.
  • Just-in-Time Compilation: The Just-in-time (JIT) Compilation is a great feature of PHP. PHP Opcache supports JIT. It’s been disabled by default, and if you enable it, JIT compiles and caches native instructions. It does not make a noticeable difference in IO-bound web applications, but provides a performance boost for CPU-heavy applications.
  • Union Types: Union Types extend type declarations (return types, parameters, and class properties) to declare more than one type.
  • Null-safe Operator: Null-safe operator provides safety in method or property chaining when the return value or property can be null.

  • Matching expressions: Match expressions are similar to switch blocks, but match blocks provide type-safe comparisons, supporting a return value that does not require break statements to break-out, and supports multiple matching values. Also it guarantees that at least one branch is matched, ensuring all cases are accounted for.

  • Weak-Maps: A WeakMap is another new feature of PHP 8.0, which allows to store and associate arbitrary values for object keys, but without preventing the garbage collector from clearing it the object falls out of scope everywhere else. A WeakMap is similar to SplObjectStorage, as in both WeakMap and splObjectStorage use objects as the key, and allows storage of arbitrary values. However, a WeakMap does not prevent the object from collecting the garbage.

New Functions and Classes of version 8.0:

PHP 8.0 introduces a few new functions to ease string inspections which contain or starts with substring, or ends with substring to replace the meticulous strpos() !== false calls that are less readable, and error-prone due to weak type comparisons.

PHP 8.0 also brings functions such as fdiv, get_resource_id, get_debug_type, and preg_last_error_msg

Apart from that, the new Stringable interface has been added and the new PhpToken class has been included which provides a more fluent Object-Oriented interface as an alternative to the legacy array-based to token_get_all function.

Deprecations: The following deprecations are being occurred in 8.0

  • PostgreSQL: Several aliased functions 
  • Deprecate required parameters after optional parameters in function/method signatures
  • `ReflectionParameter::getClass())`, `::isArray()`, and `::isCallable()` methods 
  • Disabled functions: Reflection and `get_defined_functions()` 
  • `libxml_disable_entity_loader` function 

Apart from that  two functionality or features have been adjusted. They are-

  • XMLRPC extension is moved to PECL and 
  • `FILTER_FLAG_SCHEME_REQUIRED` and `FILTER_FLAG_HOST_REQUIRED` flags are removed

Functionality or Syntax Changes in PHP 8.0: 

There have been some changes in 8.0 with previous versions and they are mentioned below-

  • Default error reporting is set to `E_ALL`
  • Inheritance rules are not applied to `private` class methods
  • Calling non-static class methods statically result in a fatal error
  • Apache Handler: Module name and file path changes
  • Locale-independent `float` to `string` casting
  • Class magic method signatures are strictly enforced
  • `substr`, `iconv_substr`, `grapheme_substr` return empty string on out-of-bound offsets
  • PHP Startup Errors are displayed by default
  • GD Extension: Windows DLL file name changed from `php_gd2.dll` to `php_gd.dll`
  • `crypt()` function requires `$salt` parameter
  • PDO: Default error mode set to exceptions
  • `@` Error Suppression operator does not silent fatal errors
  • Trailing commas are allowed in parameter lists and closure `use` lists
  • Implicit negative array key increments do not skip negative numbers
  • `XMLWriter` objects replace `xmlwriter` resources
  • OpenSSL: `resource` to object migration
  • `XMLParser` objects replace `xml` resources
  • String to number comparisons no longer coerce string to a number
  • Strict type checks on arithmetic operators
  • Sorting functions maintain positions of equal value items
  • Internal function warnings now throw `TypeError` and `ValueError` exceptions
  • Expressions can now `throw` Exceptions
  • JSON extension is always available
  • `catch` exceptions only by type
  • `+`/`-` operators take higher precedence when used with concat (`.`) operator
  • `CurlHandle` class objects replace curl handlers
  • Fatal errors on incompatible method signatures
  • Disabled functions behave as if they do not exist
  • `GdImage` class objects replace GD image resources
  • Assertions throw exceptions by default
  • Sockets extension resources (`Socket` and `AddressInfo`) are class objects

The difference between version 8.0 and 8.0.1: 

In version 8.0.1 some of the bugs of version 8.0 have been fixed, which makes the newer version more capable and flexible for the users. Some of the major bug fixings are -White space not unfolded for CC/BCC headers, Iterable not co-variant to mixed, Build of PHP extension fails due to configuration gap with libtool, stream filter loses final block of data, and so on.

Last, but not the least, RunCloud support can assist you in the update should you need any additional help, although RunCloud cannot offer any support for individual plugins that may be experiencing a conflict with the new PHP 8.0 or 8.0.1 version.

Switching PHP versions on RunCloud:

Located within your Web Application, scroll down the Navigation menu and click on Settings. Right at the very top is the setting for PHP version which you can switch from PHP 7.x to PHP 7.8. If you encounter any errors, you may switch it back immediately. It is highly recommended that if you are running a WordPress website or a live website, you do not upgrade at this time. If you are starting a new web application without WordPress or running a website that is not running on WordPress, you should be okay to upgrade, but please proceed with caution.

After selecting your PHP version, click the Update button and you will be on the new PHP version! Please check your website to make sure there are no errors. Should you encounter any issues with your upgrading to PHP 8.0 from your dashboard, do not hesitate to open a ticket to RunCloud support! If you have any suggestions or ideas for RunCloud, we are always happy to hear from you!