3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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);
based on 9LI3R
Output for 7.0.10 - 7.3.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.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