PHP 8 is released! Web hosting abreast of the new features

When the first number of a version is changed in a programming language it usually means major revisions have been developed. PHP 8 release is one of these major updates with a focus on performance thanks to its PHP 8 JIT compiler (Just in Time) added to new features which we will cover later in this article.

PHP 8 is released! Web hosting abreast of the new features.

OVHcloud web hosting team is proud to announce that the PHP Version 8.0.0 RC4 is already deployed on our web hosting solutions and waiting for your to take advantage of the PHP 8 new features offered in this release.

PHP has a long history

Up until the early 90’s websites were very limited in terms of user interactions. The only solution available to serve dynamic content to users was through CGI (Common Graphic Interface) written in C language. 

The beginnings

In 1994 Rasmus Lerdorf decided to write some of these functions for a very specific use : user tracking on his personal website. His major progress was his ability to write and read on databases through CGI functions. This allowed him to gather user information through forms, track user behavior and show specific HTML content pulled from databases.

Rasmus initially named the set of function PHP Tools which stands for “Personal Homepage” Tools as the intention was only to use these CGI functions for his own website. The function set evolved for some time on his end, changing name to FI when he focused on Form Interpreter functions and then back to PHP before releasing his freshly re-written code publicly under the PHP/FI name as a 2.0 version.

Without being aware of it Rasmus Lerdorf had built the first pillars for a complete object oriented programming language.

Rewriting the parser

PHP/FI 2.0 was still very limited but its popularity amongst developers was rising along with Apache web serving. In 1997, two students from Tel Aviv : Andi Gutmans and Zeev Suraski decided to tackle these limitations for their own e-commerce project by completely re-writing the PHP/FI parser. Rasmus, Andi and Zeev worked together on this new parser version, on the core and on integrating the language to Apache HTTP server system. They decided to rename the language to PHP for Hypertext Processor which doesn’t have a “personal” meaning anymore. This collaboration led to the 3.0 and 4.0 versions of the programming language.

Object Oriented

The PHP programming language became more and more popular. It always had its detractors mainly due to its early design and inconsistencies but around year 2000 dozens of developers were working on enhancing the language, along with the Zend engine which implies using good practices. This led to version 5 with a strong focus on enabling object-oriented programming.

Version 6 of the language did not really get released as the developers could not really come up with a complete and stable release. The main issue developers had with PHP 5 was the lack of Unicode support in Zend core. They therefore decided to use some of the v6 Unicode works into the current version 5, releasing PHP 5.4 in 2010.

PHP 7

After some discussions, the next version number finally skipped 6 to release PHP 7 in late 2015 : again, main focus was performance. This mainly thanks to a core rework to enhance the Zend engine which is now in version 3. It’s supposedly between 2 and 3 times faster than the Zend engine v2 on PHP 5.6. The main new feature introduced was the scalar type hints, along with other game breaking changes. The second main focus has been error handling to avoid fatal errors and return exceptions instead of errors when possible to catch them either on the base exception class or in the new engine exception objects. PHP 7 Also offered 64bit support which was not possible in earlier versions.

Here’s a list of the major new features PHP 7 brought to the game :

  • Scalar type hints added to Return type declarations
  • Null coalescing operators and new Spaceship operator
  • Anonymous classes (align with usage in C# and Java)
  • From Closure::bind (static method) and Closure::bindTo (method) to Closure::call(method)
  • Old and mainly unused features were also deprecated from PHP 5

As a general consensus, PHP7 and more precisely v7.4 is considered as a faster programming language than Ruby or Python.

Today, November 2020, we still have around 40% of websites developed in PHP 5. PHP 7.2 which is currently the most used PHP 7 version will lose its security updates with PHP8 release. If we add up all the discontinued versions currently used on websites we cover more than 80% of them.

Here comes PHP8 ! What’s new and what are the major benefits of this release ?

We’ve covered the game changing features when PHP 7 was released. It’s now time to go through the same exercise with version 8 and honestly this release has nothing to be ashamed of.

JIT compiles like a jet flies !

PHP 8 JIT compiler, standing for “Just In Time” brings PHP 8 speed to a new level. This is the most awaited addition to the language by the developers.

Just In Time compilation, also known as Dynamic Compilation has a strong advantage over static compilation in terms of performance.

PHP being an interpreted language, it translates the code we write into machine code which is then interpreted at runtime by the CPU.

JIT compiler is built in the runtime compiler. His role being to compile specific parts of the bytecode into machine code so that these objects code can be invoked and interpreted by the CPU efficiently instead of hosting it in the Zend VM. Indeed, this implies selecting the proper parts of the code to compile with JIT and this selection is automated thanks to recurrent code execution monitoring. The whole idea behind Just In Time compilation is to save time by using CPU native instructions : recompiling parts of the code at every call seems inefficient but running the object code into the runtime level interpreter is so efficient that it compensates the loss on the side of dynamic compilation on the fly.

Union Type support

PHP8 is now supporting union types. This allows developers to properly assign different types of values to a variable. Syntax wise the variable needs to be declared with pipe separated value types :

class Users {
    private string|array $user;

    public function setUser(string|array $user): void {
        $this->user = $user;
    }

    public function getUser(): string|array {
        return $this->user;
    }
}

Attributes v2

Before PHP 8 release we had to add metadata to declarations through doc-comments without structure.

PHP Attributes v2 are structured data allowing developers to add metadata to classes, properties, methods, functions, parameters and constants declarations. These attributes are set prior to the declarations.

Constructor property promotion

This feature is a result of the PHP developer community who wanted better ergonomics for their objects : property declaration was redundant and the syntax quite heavy. Here’s an example of how straight forward the code is to declare properties :

Before :

class humanBody {
    public int $size;
    public int $weight;

    public function __construct(
        int $size = 0,
        int $weight = 0,
            ) {
        $this->size = $size;
        $this->weight = $weight;
    }
}

After :

class humanBody {
    public function __construct(
        public int $size = 0,
        public int $weight = 0,
    ) {}
}

Named Arguments

Named arguments allows the developer to forget default values and the values order when passing the values to a function. This is done thanks to specifying the argument name.

Here’s an example from PHP official documentation :

Before PHP 8 :

htmlspecialchars($string, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);

Today with PHP 8 :

htmlspecialchars($string, double_encode: false); 

Match Expressions

Match – being an “Expression” – allows to set the value in a variable or return its value without the need for a local variable to be assigned. It also allows to forget the break; statement of the switch expression. Here’s what it looks like today compared to prior functionality with switch :

Before :

switch (example) {
  case 'example':
    $result = "Switch this";
    break;
  case example:
    $result = "Example result switched";
    break;
}
echo $result;
//> Match this

After :

echo match (example) {
  'example' => "Switch this",
  example => "Example result switched",
};
//> Example result switched

On top of this, Match can combine multiple single-line expressions (matches), comma separated. Here’s an example :

$result = match($input) {
    A, B => 'value for A and B',
    X, Y, Z => 'Same for 3 and 4',
};

Nullsafe Operator

As opposed to the null coalescing operator, the Nullsafe operator works with method calls and therefore doesn’t need to check each property before moving on to the next one or method.

More features and updates are offered in PHP8 Release ! We’ve selected the major enhancements but you might be interested into an exhaustive and detailed list of everything this release includes. You can refer to the official PHP 8 release page or in the very detailed pages on Stitcher.io

As PHP 8 is a major release, it comes with some breaking changes. You might want to ensure your code doesn’t need to be fixed on some aspects according to the different deprecated Features and backward incompatibilities.

What does this imply on your OVHcloud web hosting ?

As stated earlier, OVHcloud wants to keep your environment up to date with the latest available features offered in PHP web hosting.

We already made it available for any new web hosting plan and of course also for all existing ones. A few steps are required on your side to change your plan’s PHP version.

  1. You want to ensure your website is compatible. This on your own code :  if you have deprecated PHP functions in your code you might consider re-writing these. If you are using a CMS such as WordPress you can verify the compatibility on the CMS’ official site and ensure your plugins are compatible and therefore ready for an update. This is also the case for your framework if you’re using one. In general, you should check your website’s compatibility with PHP 8 64bit with detailed information here.
  2. When you know your site is ready for update and 100% PHP 8 64bit compatible, you can change your plan’s version directly in the OVH control panel. Detailed instructions are available on how to handle this in the control panel.

For technically advanced users, please note that you can’t directly modify the .htaccess file with our solutions. Instead you can make the changes in the .ovhconfig file available in your storage space via FTP. More details here.

Please note that JIT is not activated on our web hosting plans yet. This new feature in the programming language may lead to bugs and errors in PHP code and we want to monitor how the developers and commonly used CMS will handle this optimization feature.

ImageMagick extension will be rolled out as soon as the PHP 8 compatible libraries are available.

In general, you might want further information on :

Don’t hesitate to join our community for even more information, help and feedback !

Product Marketing Manager | + posts

Product marketing manager