3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace A { class T {} } namespace { class Test { public function first(string $str) : Closure { return function() use ($str) : int { return strlen($str); }; } public function second(): self { return self; } } $t = new Test; echo ($t->second()->first("hello"))(); }
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
Fatal error: Uncaught Error: Undefined constant "self" in /in/mToOC:19 Stack trace: #0 /in/mToOC(24): Test->second() #1 {main} thrown in /in/mToOC on line 19
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
Warning: Use of undefined constant self - assumed 'self' (this will throw an Error in a future version of PHP) in /in/mToOC on line 19 Fatal error: Uncaught TypeError: Return value of Test::second() must be an instance of Test, string returned in /in/mToOC:19 Stack trace: #0 /in/mToOC(24): Test->second() #1 {main} thrown in /in/mToOC on line 19
Process exited with code 255.
Output for 7.0.0 - 7.0.31, 7.1.0 - 7.1.23
Notice: Use of undefined constant self - assumed 'self' in /in/mToOC on line 19 Fatal error: Uncaught TypeError: Return value of Test::second() must be an instance of Test, string returned in /in/mToOC:19 Stack trace: #0 /in/mToOC(24): Test->second() #1 {main} thrown in /in/mToOC on line 19
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.38
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/mToOC on line 10
Process exited with code 255.

preferences:
239.74 ms | 402 KiB | 286 Q