3v4l.org

run code in 300+ PHP versions simultaneously
<?php class TestParent { public function __call($method, $args) { // If method call ends with 'Safe' $isSafeMethod = substr($method, -strlen('Safe')) === 'Safe'; if (!$isSafeMethod) { trigger_error('Call to undefined method '.__CLASS__.'::'.$method.'()', E_USER_ERROR); return null; } // Strip 'Safe' suffix from method name $wrappedMethodName = substr($method, 0, strpos($method, 'Safe')); try { return $this->$wrappedMethodName($args); } catch (Exception $e) { return []; } } } class TestChild extends TestParent { public function throwingMethod() { throw new RuntimeException(); } public function succeedingMethod() { return 'Success'; } } $child = new TestChild(); // With 'Safe' try-catch invoked in parent var_dump($child->throwingMethodSafe()); var_dump($child->succeedingMethodSafe()); // Without 'Safe' try-catch var_dump($child->throwingMethod());
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.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
array(0) { } string(7) "Success" Fatal error: Uncaught RuntimeException in /in/uXE2O:33 Stack trace: #0 /in/uXE2O(50): TestChild->throwingMethod() #1 {main} thrown in /in/uXE2O on line 33
Process exited with code 255.
Output for 5.6.0 - 5.6.40
array(0) { } string(7) "Success" Fatal error: Uncaught exception 'RuntimeException' in /in/uXE2O:33 Stack trace: #0 /in/uXE2O(50): TestChild->throwingMethod() #1 {main} thrown in /in/uXE2O on line 33
Process exited with code 255.

preferences:
260.38 ms | 402 KiB | 293 Q