3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class AnalyzerContainer{ public function analyze(iData $data) { switch (true) { case $data instanceof Data1: $this->_getAnalyzer1()->ananlyzeData($data); break; case $data instanceof Data2: $this->_getAnalyzer2()->ananlyzeData($data); break; default: break; }; } protected function _getAnalyzer1() { return new Analyzer1(); } protected function _getAnalyzer2() { return new Analyzer2(); } } interface iData{}; class Data1 implements iData{ public $x = null; } class Data2 implements iData{ public $y = null; } class Analyzer1 { public function ananlyzeData(Data1 $data){ echo $data->x; } } class Analyzer2 { public function ananlyzeData(Data2 $data){ echo $data->y; } } $container = new AnalyzerContainer(); $data1 = new Data1(); $container->analyze($data1);
Output for 5.0.0 - 7.1.0
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/Y8MNe on line 4
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, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/Y8MNe on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/Y8MNe on line 4
Process exited with code 255.