3v4l.org

run code in 300+ PHP versions simultaneously
<?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 8.3.0 - 8.3.4
call FUNC1 Warning: Array to string conversion in /in/9pkEq on line 27 Warning: Undefined property: foo::$Array in /in/9pkEq on line 27 Warning: Trying to access array offset on null in /in/9pkEq on line 27 Fatal error: Uncaught Error: Value of type null is not callable 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 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17
call FUNC1 Warning: Array to string conversion in /in/9pkEq on line 27 Warning: Undefined property: foo::$Array in /in/9pkEq on line 27 Warning: Trying to access array offset on value of type null in /in/9pkEq on line 27 Fatal error: Uncaught Error: Value of type null is not callable 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 7.4.0 - 7.4.33
call FUNC1 Notice: Array to string conversion in /in/9pkEq on line 27 Notice: Undefined property: foo::$Array in /in/9pkEq on line 27 Notice: Trying to access array offset on value of type null 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 7.3.32 - 7.3.33
call FUNC1 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 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31
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.5.0 - 5.5.38, 5.6.0 - 5.6.40
call FUNC1 FUNC1 call FUNC2 FUNC2 call FUNC3 FUNC3

preferences:
266.52 ms | 401 KiB | 323 Q