3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Foo { private $name = 'foo'; public static function make() { $clazz = get_class(self); echo $clazz; return new $clazz(); } } class Bar extends Foo { private $name = 'bar'; } print_r(Foo::make()); print_r(Bar::make());
based on dNZY4
Output for 7.2.0
Warning: Use of undefined constant self - assumed 'self' (this will throw an Error in a future version of PHP) in /in/7d9Rt on line 7 Warning: get_class() expects parameter 1 to be object, string given in /in/7d9Rt on line 7 Fatal error: Uncaught Error: Class name must be a valid object or a string in /in/7d9Rt:9 Stack trace: #0 /in/7d9Rt(16): Foo::make() #1 {main} thrown in /in/7d9Rt on line 9
Process exited with code 255.
Output for 7.0.0 - 7.1.10
Notice: Use of undefined constant self - assumed 'self' in /in/7d9Rt on line 7 Warning: get_class() expects parameter 1 to be object, string given in /in/7d9Rt on line 7 Fatal error: Uncaught Error: Class name must be a valid object or a string in /in/7d9Rt:9 Stack trace: #0 /in/7d9Rt(16): Foo::make() #1 {main} thrown in /in/7d9Rt on line 9
Process exited with code 255.
Output for 5.3.18 - 5.6.28
Notice: Use of undefined constant self - assumed 'self' in /in/7d9Rt on line 7 Warning: get_class() expects parameter 1 to be object, string given in /in/7d9Rt on line 7 Fatal error: Class name must be a valid object or a string in /in/7d9Rt on line 9
Process exited with code 255.