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.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
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 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 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.33, 7.4.0 - 7.4.33
Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting variable (T_VARIABLE) in /in/krssZ on line 3
Process exited with code 255.

preferences:
170.14 ms | 402 KiB | 156 Q