3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Dad { public function early() { print __CLASS__ . PHP_EOL; } public function late() { print get_class($this) . PHP_EOL; } public static function earlyStatic() { print get_class(self) . PHP_EOL; } public static function called() { print get_called_class . PHP_EOL; } } class Child extends Dad {} $parent = new Dad(); $child = new Child(); print 'PARENT' . PHP_EOL; $parent->early(); $parent->late(); $parent->earlyStatic(); $parent->called(); print 'CHILD' . PHP_EOL; $child->early(); $child->late(); $child->earlyStatic(); $child->called();
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.6
PARENT Dad Dad Fatal error: Uncaught Error: Undefined constant "self" in /in/dZ7ll:11 Stack trace: #0 /in/dZ7ll(26): Dad::earlyStatic() #1 {main} thrown in /in/dZ7ll on line 11
Process exited with code 255.
Output for 7.2.6 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
PARENT Dad Dad Warning: Use of undefined constant self - assumed 'self' (this will throw an Error in a future version of PHP) in /in/dZ7ll on line 11 Warning: get_class() expects parameter 1 to be object, string given in /in/dZ7ll on line 11 Warning: Use of undefined constant get_called_class - assumed 'get_called_class' (this will throw an Error in a future version of PHP) in /in/dZ7ll on line 14 get_called_class CHILD Dad Child Warning: Use of undefined constant self - assumed 'self' (this will throw an Error in a future version of PHP) in /in/dZ7ll on line 11 Warning: get_class() expects parameter 1 to be object, string given in /in/dZ7ll on line 11 Warning: Use of undefined constant get_called_class - assumed 'get_called_class' (this will throw an Error in a future version of PHP) in /in/dZ7ll on line 14 get_called_class
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20
PARENT Dad Dad Notice: Use of undefined constant self - assumed 'self' in /in/dZ7ll on line 11 Warning: get_class() expects parameter 1 to be object, string given in /in/dZ7ll on line 11 Notice: Use of undefined constant get_called_class - assumed 'get_called_class' in /in/dZ7ll on line 14 get_called_class CHILD Dad Child Notice: Use of undefined constant self - assumed 'self' in /in/dZ7ll on line 11 Warning: get_class() expects parameter 1 to be object, string given in /in/dZ7ll on line 11 Notice: Use of undefined constant get_called_class - assumed 'get_called_class' in /in/dZ7ll on line 14 get_called_class

preferences:
165.23 ms | 403 KiB | 181 Q