3v4l.org

run code in 300+ PHP versions simultaneously
<?php function first(/* [(array $array, $key) | $value]... */) { $count = func_num_args(); for ($i = 0; $i < $count - 1; $i++) { $arg = func_get_arg($i); if (!isset($arg)) { continue; } if (is_array($arg)) { $key = func_get_arg($i + 1); if (is_null($key) || is_string($key) || is_int($key) || is_float($key) || is_bool($key)) { if (isset($arg[$key])) { return $arg[$key]; } $i++; continue; } } return $arg; } if ($i < $count) { return func_get_arg($i); } return null; } $test = array(); echo $test ? 'truthy' : 'empty', "\r\n"; echo first(array($test[0], 0), '$test[0][0] is not set'), "\r\n"; echo $test ? 'truthy' : 'empty', "\r\n";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 2, Position 2 = 4
Branch analysis from position: 2
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
Branch analysis from position: 19
filename:       /in/TliEB
function name:  (null)
number of ops:  23
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   ASSIGN                                                   !0, <array>
   45     1      > JMPZ                                                     !0, ->4
          2    >   QM_ASSIGN                                        ~2      'truthy'
          3      > JMP                                                      ->5
          4    >   QM_ASSIGN                                        ~2      'empty'
          5    >   ECHO                                                     ~2
          6        ECHO                                                     '%0D%0A'
   46     7        INIT_FCALL                                               'first'
          8        FETCH_DIM_R                                      ~3      !0, 0
          9        INIT_ARRAY                                       ~4      ~3
         10        ADD_ARRAY_ELEMENT                                ~4      0
         11        SEND_VAL                                                 ~4
         12        SEND_VAL                                                 '%24test%5B0%5D%5B0%5D+is+not+set'
         13        DO_FCALL                                      0  $5      
         14        ECHO                                                     $5
         15        ECHO                                                     '%0D%0A'
   47    16      > JMPZ                                                     !0, ->19
         17    >   QM_ASSIGN                                        ~6      'truthy'
         18      > JMP                                                      ->20
         19    >   QM_ASSIGN                                        ~6      'empty'
         20    >   ECHO                                                     ~6
         21        ECHO                                                     '%0D%0A'
         22      > RETURN                                                   1

Function first:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 4
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 50
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 4
Branch analysis from position: 44
Branch analysis from position: 4
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 39
Branch analysis from position: 14
2 jumps found. (Code = 47) Position 1 = 21, Position 2 = 23
Branch analysis from position: 21
2 jumps found. (Code = 47) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
2 jumps found. (Code = 47) Position 1 = 27, Position 2 = 29
Branch analysis from position: 27
2 jumps found. (Code = 47) Position 1 = 30, Position 2 = 32
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 39
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
Branch analysis from position: 29
Branch analysis from position: 26
Branch analysis from position: 23
Branch analysis from position: 39
filename:       /in/TliEB
function name:  first
number of ops:  52
compiled vars:  !0 = $count, !1 = $i, !2 = $arg, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   FUNC_NUM_ARGS                                    ~4      
          1        ASSIGN                                                   !0, ~4
    7     2        ASSIGN                                                   !1, 0
          3      > JMP                                                      ->41
    9     4    >   INIT_FCALL                                               'func_get_arg'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $7      
          7        ASSIGN                                                   !2, $7
   11     8        ISSET_ISEMPTY_CV                                 ~9      !2
          9        BOOL_NOT                                         ~10     ~9
         10      > JMPZ                                                     ~10, ->12
   13    11    > > JMP                                                      ->40
   16    12    >   TYPE_CHECK                                  128          !2
         13      > JMPZ                                                     ~11, ->39
   18    14    >   INIT_FCALL                                               'func_get_arg'
         15        ADD                                              ~12     !1, 1
         16        SEND_VAL                                                 ~12
         17        DO_ICALL                                         $13     
         18        ASSIGN                                                   !3, $13
   20    19        TYPE_CHECK                                    2  ~15     !3
         20      > JMPNZ_EX                                         ~15     ~15, ->23
         21    >   TYPE_CHECK                                   64  ~16     !3
         22        BOOL                                             ~15     ~16
         23    > > JMPNZ_EX                                         ~15     ~15, ->26
         24    >   TYPE_CHECK                                   16  ~17     !3
         25        BOOL                                             ~15     ~17
         26    > > JMPNZ_EX                                         ~15     ~15, ->29
         27    >   TYPE_CHECK                                   32  ~18     !3
         28        BOOL                                             ~15     ~18
         29    > > JMPNZ_EX                                         ~15     ~15, ->32
         30    >   TYPE_CHECK                                   12  ~19     !3
         31        BOOL                                             ~15     ~19
         32    > > JMPZ                                                     ~15, ->39
   22    33    >   ISSET_ISEMPTY_DIM_OBJ                         0          !2, !3
         34      > JMPZ                                                     ~20, ->37
   24    35    >   FETCH_DIM_R                                      ~21     !2, !3
         36      > RETURN                                                   ~21
   27    37    >   PRE_INC                                                  !1
   28    38      > JMP                                                      ->40
   32    39    > > RETURN                                                   !2
    7    40    >   PRE_INC                                                  !1
         41    >   SUB                                              ~24     !0, 1
         42        IS_SMALLER                                               !1, ~24
         43      > JMPNZ                                                    ~25, ->4
   35    44    >   IS_SMALLER                                               !1, !0
         45      > JMPZ                                                     ~26, ->50
   37    46    >   INIT_FCALL                                               'func_get_arg'
         47        SEND_VAR                                                 !1
         48        DO_ICALL                                         $27     
         49      > RETURN                                                   $27
   40    50    > > RETURN                                                   null
   41    51*     > RETURN                                                   null

End of function first

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.85 ms | 1407 KiB | 16 Q