PHP is one of the easiest programming languages to learn. With a good PHP tutorial and a lot of motivation, in a few hours you can write your first scripts and execute commands. The current version, PHP 7, already brought with it a great speed optimization, which increased its prestige. Version 8.0 will be a very important update for this open source language..
Developer Brent Roose recently posted an announcement with what's new for the new version of PHP. As this update is still in the works, more changes to it may be announced in the coming months until its release.
After a long period of uncertainty, the developers have announced that the PHP 8 release will take place on November 26, 2020. This coincides with the usual 3-year PHP cycle. Also, in December 2019 PHP 7.4 was released and PHP 7.1 was discontinued. However, many web pages written in PHP still use an old version, which will soon be out of support. Keeping the web page code up to date and using the new versions of PHP can bring some benefits. The new versions offer more variety, the performance is greatly increased and the security level is higher..
If you are a customer of the IONOS web host, you can now try the beta version of PHP 8. Not yet? Then contract one of our cheap web hosting offers now. In your IONOS customer account, you can switch from the current version of PHP to the beta version of PHP 8. But beware: using the beta version of PHP 8 on production systems is not recommended.
The first alpha versions of PHP 8 have already been released. However, these are only trial versions and should not be used in online versions of web pages or applications..
Since PHP 8 is a major version, note that some older code will not be supported. Most of the changes that could present complications were already obsolete in versions 7.2, 7.3 and 7.4.
The latest changes include:
If you've kept your code up-to-date, you won't have any problems, even with the new update having incompatible changes with previous versions . In this post on GitHub you can find a complete list with all the changes.
Microsoft has announced that Windows will not support PHP 8 and later versions. However, the PHP developers have already communicated their willingness to fix this problem.
The new version of PHP is expected to introduce new features that will expand the capabilities of web developers.
The biggest novelty will be the JIT compiler , which will improve performance considerably. PHP is not compiled, but is interpreted line by line. The JIT ( Just in Time ) compiler would compile some of the code at runtime , so it would work very similar to a cached version of the code. With this, performance should improve considerably.
This PHP 8 feature has already been tested very successfully by Pedro Escudero. Used a simple script to compare versions 5.3, 7.4 and 8 (with and without JIT). To do this, he ran the script a hundred times in each version and calculated the average time.
The result was the following values:
Although the difference between version 7.4 and version 8 without JIT is not very big, between version 7.4 and 8 with JIT it is significant. The JIT compiler provides a performance improvement of more than 45% .
In earlier versions of the scripting language , the JSON extension could be optionally disabled. However, since JSON is a very important data format, the PHP developers have decided to leave the extension enabled all the time. This should simplify working with PHP.
The types junction also appear in other languages such as C / C ++, or Haskell typescript. They allow to create unions of two or more types of data, being able to use any of them. In code, this would look like the following:
public function foo(Foo|Bar $input): int|float;
However, there is a limitation. Void cannot be part of a union type , as it does not return any value. Also, nullable unions can be written with | null or ? , as we show you in this example:
public function foo(Foo|null $foo): void; public function bar(?Bar $bar): void;
Static is a special class name and in the new version it will be a valid return type next to self & parent.
In PHP 7.4 the WeakRefs already appeared, and now with WeakMaps an extension of this function is offered. WeakMaps and WeakRefs can be used to delete objects, only if the cache still references the object's feature classes. This offers resource-saving object management . An example taken from the documentation:
class FooBar { private WeakMap $cache; public function getSomethingWithCaching(object $obj) { return $this->cache[$obj] ??= $this->computeSomethingExpensive($obj); } // ... }
In previous versions you had to use get_class () to assign a class to objects. Now you can apply :: class directly to objects. This helps keep the code cleaner.
Stringable interface implements an interface automatically. Until now, this step had to be done manually. This can be done for all strings or for those where __toString () is implemented. In the code it would read as follows:
class Foo { public function __toString(): string { return 'foo'; } } function bar(Stringable $stringable) { /* ? */ } bar(new Foo()); bar('abc');
With PHP 8 it will be considerably easier to convert DateTime . The developers have added DateTime :: createFromInterface () and DatetimeImmutable :: createFromInterface (). In this way DateTime and DateTimeImmutable can be converted from one to the other.
With fdiv a division by 0 will be possible. Now INF, -ING or NAN is obtained as return value.
The new version will include correct type annotations for all internal functions and methods.
Previously, only user-defined functions triggered TypeErrors. Internal functions issued a warning and returned null . With PHP 8, internal functions will also produce TypeErrors.
Until now there were many errors that only issued a warning. This will be updated. Here you will find a complete list of new error messages in PHP.
Errors that until now were ignored without generating a warning, will be presented as E_ALL, E_NOTICE and E_DEPRECATED. These bugs existed prior to version 8, but were not visibly reported.
This new feature will also aid in bug detection. Instead of suppressing them with the @ operator as was done until now, display_errors = Off should be used on the server.
This feature was already introduced in PHP 7.4 and will now be fully functional. PHP will now react more intelligently to multiple operators. As an example we show you the following code:
Until now, PHP interpreted
echo "sum: " . $a + $b;
as
echo ("sum: " . $a) + $b;
Now PHP 8 will interpret it as
echo "sum: " . ($a + $b);
The signatures will be exchanged. Previously, Reflection appeared as follows:
ReflectionClass::newInstance($args); ReflectionFunction::invoke($args); ReflectionMethod::invoke($object, $args);
In PHP 8, it will be written such that:
ReflectionClass::newInstance(...$args); ReflectionFunction::invoke(...$args); ReflectionMethod::invoke($object, ...$args);
To use PHP 7 and PHP 8 simultaneously, proceed as follows:
ReflectionClass::newInstance($arg = null, ...$args); ReflectionFunction::invoke($arg = null, ...$args); ReflectionMethod::invoke($object, $arg = null, ...$args);
These features of PHP 8 are already confirmed. Still, more news is expected in the months leading up to its launch.