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 = 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
Fatal error: Default value for property of type closure may not be null. Use the nullable type ?closure to allow null default value in /in/SuLb9 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/SuLb9 on line 3
Process exited with code 255.

preferences:
215.29 ms | 1399 KiB | 74 Q