3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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"))(); }
based on cHa3M
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/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.1.10
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.3.20 - 5.6.28
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/mToOC on line 10
Process exited with code 255.