3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyMath { /** * @throws Exception */ public function calculateMedian(array $array): int|float { if (!$array) { throw new LengthException('Cannot calculate median because Argument #1 ($array) is empty'); } sort($array); $middleIndex = count($array) / 2; if (is_float($middleIndex)) { return $array[(int) $middleIndex]; } return ($array[$middleIndex] + $array[$middleIndex - 1]) / 2; } } $math = new MyMath; var_export($math->calculateMedian([1, 2, 3, 4, 5]));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/v0WrH
function name:  (null)
number of ops:  10
compiled vars:  !0 = $math
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   NEW                                              $1      'MyMath'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   24     3        INIT_FCALL                                               'var_export'
          4        INIT_METHOD_CALL                                         !0, 'calculateMedian'
          5        SEND_VAL_EX                                              <array>
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Class MyMath:
Function calculatemedian:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/v0WrH
function name:  calculateMedian
number of ops:  28
compiled vars:  !0 = $array, !1 = $middleIndex
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
   10     1        BOOL_NOT                                         ~2      !0
          2      > JMPZ                                                     ~2, ->7
   11     3    >   NEW                                              $3      'LengthException'
          4        SEND_VAL_EX                                              'Cannot+calculate+median+because+Argument+%231+%28%24array%29+is+empty'
          5        DO_FCALL                                      0          
          6      > THROW                                         0          $3
   13     7    >   INIT_FCALL                                               'sort'
          8        SEND_REF                                                 !0
          9        DO_ICALL                                                 
   14    10        COUNT                                            ~6      !0
         11        DIV                                              ~7      ~6, 2
         12        ASSIGN                                                   !1, ~7
   15    13        TYPE_CHECK                                   32          !1
         14      > JMPZ                                                     ~9, ->19
   16    15    >   CAST                                          4  ~10     !1
         16        FETCH_DIM_R                                      ~11     !0, ~10
         17        VERIFY_RETURN_TYPE                                       ~11
         18      > RETURN                                                   ~11
   18    19    >   FETCH_DIM_R                                      ~12     !0, !1
         20        SUB                                              ~13     !1, 1
         21        FETCH_DIM_R                                      ~14     !0, ~13
         22        ADD                                              ~15     ~12, ~14
         23        DIV                                              ~16     ~15, 2
         24        VERIFY_RETURN_TYPE                                       ~16
         25      > RETURN                                                   ~16
   19    26*       VERIFY_RETURN_TYPE                                       
         27*     > RETURN                                                   null

End of function calculatemedian

End of class MyMath.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.56 ms | 1400 KiB | 17 Q