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 ; 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 = serialize($pont1); echo $chaine; $pont3 = unserialize($chaine); var_dump($pont3);
Output for 8.0.0 - 8.0.12, 8.1rc1 - rc3
object(Pont)#1 (3) { ["taille":"Pont":private]=> object(Closure)#3 (1) { ["this"]=> *RECURSION* } ["name":protected]=> string(11) "towerBridge" ["tablier":protected]=> object(Tablier)#2 (2) { ["longueur"]=> float(386) ["largeur"]=> float(16) } } O:4:"Pont":2:{s:7:"*name";s:11:"towerBridge";s:10:"*tablier";O:7:"Tablier":2:{s:8:"longueur";d:386;s:7:"largeur";d:16;}}object(Pont)#6 (3) { ["taille":"Pont":private]=> object(Closure)#8 (1) { ["this"]=> *RECURSION* } ["name":protected]=> string(11) "towerBridge" ["tablier":protected]=> object(Tablier)#7 (2) { ["longueur"]=> float(386) ["largeur"]=> float(16) } }
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/cb0Fn on line 3
Process exited with code 255.

preferences:
18.57 ms | 461 KiB | 5 Q