3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class MyClass { function foo() { return 'foo'; } }; class MyOtherClass { function __construct($klass) { $this->klass = $klass; } function get_instance() { return new $this->klass(); } } $factory = new MyOtherClass(MyClass); $obj = $factory->get_instance(); ?> // <h1> value should equal foo <h1><?php echo $obj->foo();?></h1>
Output for 5.0.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Notice: Use of undefined constant MyClass - assumed 'MyClass' in /in/F4ZLJ on line 18 // <h1> value should equal foo <h1>foo</h1>
Output for 4.3.2 - 4.4.9
Notice: Undefined property: klass in /in/F4ZLJ on line 14 Fatal error: Cannot instantiate non-existent class: in /in/F4ZLJ on line 14
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Notice: Undefined property: klass in /in/F4ZLJ on line 14 Fatal error: Cannot instantiate non-existent class: in /in/F4ZLJ on line 14