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 null; 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.11, 8.1rc1 - rc3
Parse error: syntax error, unexpected identifier "null", expecting "," or ";" in /in/Ibian on line 10
Process exited with code 255.
Output for 7.3.0 - 7.3.31, 7.4.0 - 7.4.24
Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting variable (T_VARIABLE) in /in/Ibian on line 3
Process exited with code 255.

preferences:
22.06 ms | 906 KiB | 6 Q