PHP 8 interview: “JIT will bring the language to a whole new level”

Share
  • January 23, 2020

JAXenter: What do we know about the release date for PHP 8.0?

Níckolas: Currently it is nearly impossible to foresee any dates for PHP 8.0 given version 7.4 was released less than three months ago. There were some discussions on the mailing list proposing opening version 8.0 for alpha short after releasing PHP 7.4;

One possibility for 2020 is to have monthly previews very soon until it hits alpha version. This was suggested by Sara Golemon here: https://externals.io/message/105001#105010

Some websites are already trying to create chaos around the subject, stating that PHP 8 might not come out. Mostly due to this post from Dmitry Stogov, Matthew Weier O’Phinney and Enrico Zimuel. But it doesn’t change much: PHP 8 development is still strong and fast-paced.

The Just In Time compiler is definitely the biggest deal for this version, bringing virtually no changes to how code looks like but potentially many unexpected behaviours to PHP platforms. So I strongly believe many previews will be delivered in 2020 way before we hit any alpha, to make sure all current features are at least stable.

JAXenter: What features are already confirmed for PHP 8.0? Please give an example with code.

Níckolas: Just In Time (JIT) compiler will be in. There’s no code I can share about it, as it will change how PHP code is interpreted.

Union Types will also be in. They will allow variable types to have more than one type possibility. An example from the official feature proposal is the following:

class Number {
private int|float $number;

public function setNumber(int|float $number): void {
$this->number = $number;
}

public function getNumber(): int|float {
return $this->number;
}
}

Notice how $number can be an int or float there.

A new class called WeakMap was also added. This class allows users to create maps where objects are keys (like the SplObjectStorage). The trick here is that this reference between objects and maps themselves is a weak reference. Meaning when the object gets destroyed, the value on the map will also be destroyed:

$map = new WeakMap;
$obj = new stdClass;
$map[$obj] = 42;
var_dump($map);
// object(WeakMap)#1 (1) {
//   [0]=>
//   array(2) {
//     ["key"]=>
//     object(stdClass)#2 (0) {
//     }
//     ["value"]=>
//     int(42)
//   }
// }
 
// The object is destroyed here, and the key is automatically removed from the weak map.
unset($obj);
var_dump($map);
// object(WeakMap)#1 (0) {
// }

Also this is not yet included in the official docs, but a new method was added to the DateTime and DateTimeImmutable classes called createFromInterface(). This will act as createFromMutable() or createFromImmutable() but accepts a DateTimeInterface instead. You can see the commit here: https://github.com/php/php-src/commit/1658b5babc34c46b3b78b852e7a5f134845ace7c

SEE ALSO: How to get ready for PHP 8

Besides those there are some minor changes to make the DOM API compatible with the latest standards and a couple of behaviours changed.

JAXenter: Which of these features is your personal highlight and why?

Níckolas: By far JIT is the most important one here. Even though it should not bring crazy performance improvements to web applications written in PHP, it will bring the language to a whole new level. With JIT, PHP won’t depend on C features anymore and will be able to develop language-specific features. It will also bring the possibility to the language to be used for CPU-intensive tasks, meaning PHP could be, in the near future, considered for things people nowadays don’t even imagine. Things like Machine Learning, Game Development or User Interface development, for example.

SEE ALSO: Long live PHP!

JAXenter: Are there more features planned to be added to the upcoming version?

Níckolas: I don’t see any other big feature on the roadmap at least for now. There are some behavioral changes in pending vote phase, things like error handling and comparison operators.

I hope that was insightful for you. You can always come back to my post to check for updates on this version.

Thanks very much!

The post PHP 8 interview: “JIT will bring the language to a whole new level” appeared first on JAXenter.

Source : JAXenter