3v4l.org

run code in 300+ PHP versions simultaneously
<?php class X { public static function test(X $x) { var_dump($x); if (version_compare(PHP_VERSION, '8.1') >= 0) { var_dump(serialize($x)); } } } class Y extends X { private $value = 1; private function __debugInfo() { return array('value' => $this->value); } private function __sleep() { return array('value'); } private function __destruct() {} } X::test(new X()); X::test(new Y());
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
Warning: The magic method Y::__debugInfo() must have public visibility in /in/bKijA on line 15 Warning: The magic method Y::__sleep() must have public visibility in /in/bKijA on line 19 object(X)#1 (0) { } string(12) "O:1:"X":0:{}" object(Y)#1 (1) { ["value"]=> int(1) } string(31) "O:1:"Y":1:{s:8:"Yvalue";i:1;}" Fatal error: Uncaught Error: Call to private Y::__destruct() from global scope in /in/bKijA:27 Stack trace: #0 {main} thrown in /in/bKijA on line 27
Process exited with code 255.

preferences:
71.84 ms | 407 KiB | 5 Q