3v4l.org

run code in 300+ PHP versions simultaneously
<?php function anon() { static $i = 0; return eval(sprintf('return new class { public $prop%s; };', ++$i)); } $c1 = anon(); $c1->prop1 = 'hello'; $c2 = anon(); var_dump($c1, $c2, $c1->prop1, $c1->prop2);
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.7
Warning: Undefined property: class@anonymous::$prop2 in /in/Eq3Di on line 13 object(class@anonymous)#1 (1) { ["prop1"]=> string(5) "hello" } object(class@anonymous)#2 (1) { ["prop2"]=> NULL } string(5) "hello" NULL
Output for 7.4.3 - 7.4.33
Notice: Undefined property: class@anonymous::$prop2 in /in/Eq3Di on line 13 object(class@anonymous)#1 (1) { ["prop1"]=> string(5) "hello" } object(class@anonymous)#2 (1) { ["prop2"]=> NULL } string(5) "hello" NULL
Output for 7.0.10 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0
Notice: Undefined property: class@anonymous::$prop2 in /in/Eq3Di on line 13 object(class@anonymous)#1 (1) { ["prop1"]=> string(5) "hello" } object(class@anonymous)#2 (1) { ["prop1"]=> NULL } string(5) "hello" NULL
Output for 7.3.32 - 7.3.33
object(class@anonymous)#1 (1) { ["prop1"]=> string(5) "hello" } object(class@anonymous)#2 (1) { ["prop1"]=> NULL } string(5) "hello" NULL
Output for 7.0.0 - 7.0.9
Notice: Undefined property: class@anonymous::$prop1 in /in/Eq3Di on line 13 object(class@anonymous)#1 (1) { ["prop2"]=> string(5) "hello" } object(class@anonymous)#2 (1) { ["prop2"]=> NULL } NULL string(5) "hello"
Output for 5.6.0 - 5.6.38
Parse error: syntax error, unexpected 'class' (T_CLASS) in /in/Eq3Di(6) : eval()'d code on line 1 Warning: Creating default object from empty value in /in/Eq3Di on line 10 Parse error: syntax error, unexpected 'class' (T_CLASS) in /in/Eq3Di(6) : eval()'d code on line 1 Notice: Undefined property: stdClass::$prop2 in /in/Eq3Di on line 13 object(stdClass)#1 (1) { ["prop1"]=> string(5) "hello" } bool(false) string(5) "hello" NULL

preferences:
194.63 ms | 402 KiB | 284 Q