3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php declare(strict_types=1); class A { public function test(): void { return; } public function test2(): void { return null; } } (new A())->test(); echo 'First OK'; (new A())->test2();
based on BPdH6
Output for 7.1.0 - 7.1.7
Fatal error: A void function must not return a value (did you mean "return;" instead of "return null;"?) in /in/FHhh4 on line 14
Process exited with code 255.
Output for 7.0.0 - 7.0.20
Fatal error: Uncaught TypeError: Return value of A::test() must be an instance of void, none returned in /in/FHhh4:9 Stack trace: #0 /in/FHhh4(18): A->test() #1 {main} thrown in /in/FHhh4 on line 9
Process exited with code 255.
Output for hhvm-3.15.4
Fatal error: Uncaught TypeError: Value returned from method A::test() must be of type void, null given in /in/FHhh4:9 Stack trace: #0 /in/FHhh4(18): A->test() #1 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Warning: Unsupported declare 'strict_types' in /in/FHhh4 on line 3 Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/FHhh4 on line 7
Process exited with code 255.