<?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.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)
}
}
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 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)
}
}
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.33, 7.4.0 - 7.4.33
- Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting variable (T_VARIABLE) in /in/cb0Fn on line 3
Process exited with code 255.
preferences:
174.28 ms | 402 KiB | 156 Q