3v4l.org

run code in 300+ PHP versions simultaneously
<?php $x = 4; if($x == 1){ class X{} $x = []; $x["x"] = new X(); $x["y"] = "5"; echo serialize($x); // a:2:{s:1:"x";O:1:"X":0:{}s:1:"y";s:1:"5";} } elseif($x == 2){ $x = unserialize('a:2:{s:1:"x";O:1:"X":0:{}s:1:"y";s:1:"5";}'); print_r($x); /* Array ( [x] => __PHP_Incomplete_Class Object ( [__PHP_Incomplete_Class_Name] => X ) [y] => 5 ) */ } elseif($x == 3){ enum Y{ case Y; } $x = []; $x["x"] = Y::Y; $x["y"] = "5"; echo serialize($x); // a:2:{s:1:"x";E:3:"Y:Y";s:1:"y";s:1:"5";} } elseif($x == 4){ $x = unserialize('a:2:{s:1:"x";E:3:"Y:Y";s:1:"y";s:1:"5";}'); print_r($x); }
Output for 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
Warning: unserialize(): Class 'Y' not found in /in/u130I on line 34 Warning: unserialize(): Error at offset 13 of 40 bytes in /in/u130I on line 34
Output for 8.2.0 - 8.2.29
Warning: unserialize(): Class 'Y' not found in /in/u130I on line 34 Notice: unserialize(): Error at offset 13 of 40 bytes in /in/u130I on line 34

preferences:
68.07 ms | 407 KiB | 5 Q