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 = serialise($pont1); echo $chaine; $pont3 = unserialise($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) } } Fatal error: Uncaught Error: Call to undefined function serialise() in /in/krssZ:33 Stack trace: #0 {main} thrown in /in/krssZ on line 33
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/krssZ on line 3
Process exited with code 255.

preferences:
19.87 ms | 461 KiB | 5 Q