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'); // идентичный результат
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/CnoKD
function name:  (null)
number of ops:  20
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   INIT_STATIC_METHOD_CALL                                  'ExcController', 'getExceptionClassByCode'
          1        SEND_VAL                                                 22
          2        DO_FCALL                                      0  $0      
          3        FETCH_CLASS                                   0  $1      $0
          4        NEW                                              $2      $1
          5        DO_FCALL                                      0          
          6      > THROW                                         0          $2
   24     7*       INIT_STATIC_METHOD_CALL                                  'ExcController', 'getExceptionClassByCode'
          8*       SEND_VAL                                                 22
          9*       DO_FCALL                                      0  $4      
         10*       FETCH_CLASS                                   0  $5      $4
         11*       NEW                                              $6      $5
         12*       SEND_VAL_EX                                              'qwerty'
         13*       DO_FCALL                                      0          
         14*       THROW                                         0          $6
   25    15*       INIT_STATIC_METHOD_CALL                                  'ExcController', 'throwExceptionByCode'
         16*       SEND_VAL                                                 22
         17*       SEND_VAL                                                 'qwerty'
         18*       DO_FCALL                                      0          
         19*     > RETURN                                                   1

Class MyExc1: [no user functions]
Class MyExc2: [no user functions]
Class ExcController:
Function getexceptionclassbycode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CnoKD
function name:  getExceptionClassByCode
number of ops:  5
compiled vars:  !0 = $curlErr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   14     1        FETCH_STATIC_PROP_R          unknown             ~1      'map'
          2        FETCH_DIM_R                                      ~2      ~1, !0
          3      > RETURN                                                   ~2
   15     4*     > RETURN                                                   null

End of function getexceptionclassbycode

Function throwexceptionbycode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/CnoKD
function name:  throwExceptionByCode
number of ops:  10
compiled vars:  !0 = $curlErr, !1 = $msg
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   18     2        FETCH_STATIC_PROP_R          unknown             ~2      'map'
          3        FETCH_DIM_R                                      ~3      ~2, !0
          4        FETCH_CLASS                                   0  $4      ~3
          5        NEW                                              $5      $4
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0          
          8      > THROW                                         0          $5
   19     9*     > RETURN                                                   null

End of function throwexceptionbycode

End of class ExcController.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.24 ms | 1399 KiB | 13 Q