3v4l.org

run code in 300+ PHP versions simultaneously
<?php // https://ru.stackoverflow.com/questions/1444784 class MyExc1 extends \Exception {} class MyExc2 extends \Exception {} class ExcController { private static $map = [ 22 => MyExc1::class, 28 => MyExc2::class, ]; public static function getExceptionClassByCode($curlErr) { return self::$map[$curlErr]; } public static function throwExceptionByCode($curlErr, $msg) { throw new self::$map[$curlErr]($msg); } } // обратите внимание на круглые скобки /* 1 */ throw new (ExcController::getExceptionClassByCode(22)); // throw new (MyExc1); /* 2 */ throw new (ExcController::getExceptionClassByCode(22))('qwerty'); // throw new (MyExc1)('qwerty') /* 3 */ ExcController::throwExceptionByCode(22, 'qwerty'); // идентичный результат
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught MyExc1 in /in/CnoKD:23 Stack trace: #0 {main} thrown in /in/CnoKD on line 23
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
41.43 ms | 401 KiB | 8 Q