3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Tablier { public function __construct(public float $longueur, public float $largeur){ } } class Pont { private closure $taille = nullable; public function __sleep() { return array('name','tablier'); } public function __wakeup() { $this->taille = fn() => $this->tablier->longueur * $this->tablier->largeur; } public function __construct(protected string $name, protected Tablier $tablier) { $this->taille = fn() => $this->tablier->longueur * $this->tablier->largeur; } public function __clone(){ $this->tablier = clone $this->tablier; } } $pont1 = new Pont("towerBridge", new Tablier(386,16)); var_dump($pont1); $pont2 = clone $pont1; $chaine = serialise($pont1); echo $chaine; $pont3 = unserialise($chaine); var_dump($pont3);
Output for 8.0.0 - 8.0.12, 8.1rc1 - rc3
Fatal error: Uncaught Error: Undefined constant "nullable" in /in/UjT6Q:30 Stack trace: #0 {main} thrown in /in/UjT6Q on line 30
Process exited with code 255.
Output for 7.3.0 - 7.3.31, 7.4.0 - 7.4.25
Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting variable (T_VARIABLE) in /in/UjT6Q on line 3
Process exited with code 255.

preferences:
20.57 ms | 529 KiB | 6 Q