3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Foo { class Bar { function __construct(){ echo get_called_class() . PHP_EOL; echo get_class($this) . PHP_EOL; echo __CLASS__ . PHP_EOL; echo get_class(self) . PHP_EOL; if (version_compare(PHP_VERSION, '5.5.0') >= 0) { echo Bar::class . PHP_EOL; } } } $oBar = new Bar(); } #EOF
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
Foo\Bar Foo\Bar Foo\Bar Fatal error: Uncaught Error: Undefined constant "Foo\self" in /in/rQMb6:10 Stack trace: #0 /in/rQMb6(17): Foo\Bar->__construct() #1 {main} thrown in /in/rQMb6 on line 10
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Foo\Bar Foo\Bar Foo\Bar Warning: Use of undefined constant self - assumed 'self' (this will throw an Error in a future version of PHP) in /in/rQMb6 on line 10 Warning: get_class() expects parameter 1 to be object, string given in /in/rQMb6 on line 10 Foo\Bar
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33
Foo\Bar Foo\Bar Foo\Bar Notice: Use of undefined constant self - assumed 'self' in /in/rQMb6 on line 10 Warning: get_class() expects parameter 1 to be object, string given in /in/rQMb6 on line 10 Foo\Bar
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in /in/rQMb6 on line 12
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected T_CLASS, expecting T_STRING or T_VARIABLE or '$' in /in/rQMb6 on line 12
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_STRING in /in/rQMb6 on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING in /in/rQMb6 on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/rQMb6 on line 2
Process exited with code 255.

preferences:
324.5 ms | 401 KiB | 460 Q