3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php interface response { public function getResponseClass(); } class foo implements response { public $type = 'foo'; public function getResponseClass() { return 'hello'; } } class bar implements response { public $type = 'bar'; public function getResponseClass() { return 'world'; } } class hello { } class world { } class process { public function test1($a) { switch ($a->type) { case 'foo': return new hello(); case 'bar': return new world(); } } public function test2($a) { return $a->getResponseClass(); } } $p = new process; var_dump($p->test1(new bar())); var_dump($p->test2(new bar()));
based on WAIUR
Output for 5.0.0 - 7.2.6
object(world)#3 (0) { } string(5) "world"
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING in /in/vJ2hJ on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING in /in/vJ2hJ on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/vJ2hJ on line 3
Process exited with code 255.