Home Build Automation PHP 8 Released

PHP is one of the programming languages that are easiest to use and learn, Now PHP 8 has been officially released and its new major update contains a bunch of optimizations and powerful features to the language which allows us to write better code and build more powerful applications. You can install the latest version PHP 8 via EasyApache 4 on a cPanel server but its main requirement is that the server needs to be running CentOS 7 or newer, as PHP 8 does not support on CentOS 6 servers.

Undoubtedly, the JIT compiler (“Just In Time”) is the most focusing deal for this latest version of the programming language. JIT compiler slightly increase the performance when it comes up with PHP 8 and it acts as a cached version for PHP codes and compiles the parts of codes at run time. Due to the cached version, it makes a  massive change in the performance.  PHP version 8 without JIT is much similar to PHP version 7.4 but using JIT to PHP 8 make significant changes and this performance can simply show through the below image.

 As we mentioned above, PHP 8 JIT useful in terms of performance, for which it is true and easy for Magento 2 associated web application in terms of improving performance. How it is fair to say that the feature completely matches with its tasks on simple code.

The following are the list of features and performance comes up with PHP 8 and these features should make PHP more reliable and efficient.

  • Constructor Property Promotion
  • Validation for Abstract Trait Methods
  • Arrays Starting With a Negative Index
  • Incompatible Method Signatures
  • Allow ::class syntax on objects
  • Union Types 2.0
  • Consistent Type Errors for Internal Functions
  • throw Expression
  • Trailing Comma in Parameter List
  • Attributes v2
  • Weak Maps
  • Named Arguments
  • Nullsafe Operator
  • Saner String to Number Comparisons
  • Saner Numeric Strings
  • Match Expression v2
  • Stricter Type Checks for Arithmetic/Bitwise Operators

PHP 8 supports for Union types, Union types accept values that can be of different types, two or more types can form a union. With the help of PHP 8, it is much easier and helpful to convert DateTime. The developers have added DateTime::createFromInterface() and DatetimeImmutable::createFromInterface(). This makes it easier and workable to convert DateTime and DateTimeImmutable .

This new version adds correct type annotations for all internal functions and methods. When it begins with PHP 8, internal functions will also return TypeErrors. Attributes, also known as annotations in C#, are a form of structured metadata in which attributes on a program element be a piece of data added to the program which is used to establish element with extra code. Before the invention of latest version PHP 8, the only way to add these metadata to declarations of classes, functions etc we used doc-comments. Now, the contribution from attributes for PHP establishes them as the construction of structured, syntactic metadata that can be added to those declarations of classes, properties, functions, methods, parameters, and constants.

Trailing commas (final commas) are commas at the end of a series of values in an array, it will be useful when we are considering to add elements or parameters in a JavaScript code because when a line ends up with trailing commas we can do modifications or changes by simply adding new line without effecting them to the previous line. Trailing Comma in Parameter List is one of the features introduced by PHP 8 with function, method and closures.

 

 

 

 

 

 

Before PHP 8, the statement throw is not possible to use it in places where only an expression is allowed. Now it is possible to convert throw statement to an expression so that it can be used in any context where expressions are allowed.

WeakMap object: In WeakMap keys plays an important role, that is collection of these key pairs are referred to as WeakMap object in which keys are weakly named. The extensions and modules which are not currently available and incompatible with the latest version of PHP-8 are listed below:

  • PHP-PSR
  • Snuffleupagus -This module is specially designed for PHP 7.* to reduce the website attacks without touching the PHP codes. Hence currently this is not available on PHP 8.*
  • Phalcon 4
  • ionCube 10
  • Memcache
  • SourceGuardian – Like other modules, it also helps to protect our PHP source code with the help of this advanced PHP encoder but it provides full support only for PHP versions 4, 5, 7 including 7.4.

Some software which is incompatible with the latest version of PHP 8 are listed below:

  • DSO — DSO is one of the PHP handler used to execute the PHP scripts in a faster way as an apache module. As we know this to be considered as the fasted handler for executes PHP scripts most of us still using DSO, but when it comes to the latest version of PHP, 8.* cPanel & WHM currently does not provide support for the use of DSO handler.
  • The XMLRPC extensions — This extension moved to PECL.
  • The JSON extension — This component is appended in PHP 8 by default.

The following are the list of new functions PHP 8 provides to the language:

  • str_contains
  • str_starts_with() and str_ends_with()
  • get_debug_type

The get_debug_type is similar to gettype function, which returns a type of the variable and resolves the class names. Hence it is considered as a great improvement for the language.

The str_starts_with() and str_ends_with() two new functions will help to find out whether a given string is present at the beginning or end of a haystack string. These two functions are considered as case sensitive because there are no flags or other functions to make them case sensitive.

Leave a Comment