3v4l.org

run code in 300+ PHP versions simultaneously
<?php class F { private string $bar; public function __construct(private string $foo, string $bar){ $this->bar = $bar; } public function __sleep(): array { return array_keys(get_object_vars($this)); } public function getFoo():string { return $this->foo; } public function getBar():string { return $this->bar; } } $g = new F('this is a private variable', 'so is this'); class G extends F {} $s = serialize($g); var_export($s); $n = unserialize($s); echo \PHP_EOL; echo $n->getFoo(); echo \PHP_EOL; echo $n->getBar(); $h = new G('This is an extension', 'of the other one'); $s = serialize($h); echo \PHP_EOL; var_export($s); $n = unserialize($s); echo \PHP_EOL; echo $n->getFoo(); echo \PHP_EOL; echo $n->getBar();
Output for git.master, git.master_jit, rfc.property-hooks
'O:1:"F":2:{s:6:"' . "\0" . 'F' . "\0" . 'bar";s:10:"so is this";s:6:"' . "\0" . 'F' . "\0" . 'foo";s:26:"this is a private variable";}' this is a private variable so is this Warning: serialize(): "bar" returned as member variable from __sleep() but does not exist in /in/d6WN9 on line 32 Warning: serialize(): "foo" returned as member variable from __sleep() but does not exist in /in/d6WN9 on line 32 'O:1:"G":0:{}' Fatal error: Uncaught Error: Typed property F::$foo must not be accessed before initialization in /in/d6WN9:13 Stack trace: #0 /in/d6WN9(37): F->getFoo() #1 {main} thrown in /in/d6WN9 on line 13
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
46.8 ms | 406 KiB | 5 Q