3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class foo { private $functions = array( array('funcName' => 'FUNC1'), array('funcName' => 'FUNC2'), array('funcName' => 'FUNC3') ); function FUNC1() { echo 'FUNC1', PHP_EOL, PHP_EOL; } function FUNC2() { echo 'FUNC2', PHP_EOL, PHP_EOL; } function FUNC3() { echo 'FUNC3', PHP_EOL, PHP_EOL; } /** this worked only up to PHP 5.6.16 */ public function callAllFunctions() { foreach ($this->functions as $values) { echo 'call ', $values['funcName'], PHP_EOL; $this->$values['funcName'](); } } /** this code must be used in PHP 7.x public function callAllFunctions() { foreach ($this->functions as $values) { echo 'call ', $values['funcName'], PHP_EOL; $fncName = $values['funcName']; $this->$fncName(); } } */ } $test = new foo(); $test->callAllFunctions();
Output for 7.0.0 - 7.2.0
call FUNC1 Notice: Array to string conversion in /in/9pkEq on line 27 Notice: Undefined property: foo::$Array in /in/9pkEq on line 27 Fatal error: Uncaught Error: Function name must be a string in /in/9pkEq:27 Stack trace: #0 /in/9pkEq(43): foo->callAllFunctions() #1 {main} thrown in /in/9pkEq on line 27
Process exited with code 255.
Output for 5.3.21 - 5.6.28
call FUNC1 FUNC1 call FUNC2 FUNC2 call FUNC3 FUNC3