3v4l.org

run code in 500+ PHP versions simultaneously
<?php function test($var, array $G, array $P) { if (empty($var)) { return; } if (isset($P[$var])) { $value = $P[$var]; } elseif (isset($G[$var])) { $value = $G[$var]; } else { $value = null; } return $value; } function test2($var, array $G, array $P) { return $P[$var] ?? $G[$var] ?? null; } $G = ['a' => 'A', 'b' => '', 'c' => 'C']; $P = ['b' => 'B', 'c' => '']; var_dump(test('a', $G, $P)) . PHP_EOL; var_dump(test('b', $G, $P)) . PHP_EOL; var_dump(test('c', $G, $P)) . PHP_EOL; var_dump(test('', $G, $P)) . PHP_EOL; print '-----' . PHP_EOL; var_dump(test2('a', $G, $P)) . PHP_EOL; var_dump(test2('b', $G, $P)) . PHP_EOL; var_dump(test2('c', $G, $P)) . PHP_EOL; var_dump(test2('', $G, $P)) . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DVp4L
function name:  (null)
number of ops:  84
compiled vars:  !0 = $G, !1 = $P
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   22     0  E >   ASSIGN                                                       !0, <array>
   23     1        ASSIGN                                                       !1, <array>
   25     2        INIT_FCALL                                                   'var_dump'
          3        INIT_FCALL                                                   'test'
          4        SEND_VAL                                                     'a'
          5        SEND_VAR                                                     !0
          6        SEND_VAR                                                     !1
          7        DO_FCALL                                          0  $4      
          8        SEND_VAR                                                     $4
          9        DO_ICALL                                             $5      
         10        CONCAT                                               ~6      $5, '%0A'
         11        FREE                                                         ~6
   26    12        INIT_FCALL                                                   'var_dump'
         13        INIT_FCALL                                                   'test'
         14        SEND_VAL                                                     'b'
         15        SEND_VAR                                                     !0
         16        SEND_VAR                                                     !1
         17        DO_FCALL                                          0  $7      
         18        SEND_VAR                                                     $7
         19        DO_ICALL                                             $8      
         20        CONCAT                                               ~9      $8, '%0A'
         21        FREE                                                         ~9
   27    22        INIT_FCALL                                                   'var_dump'
         23        INIT_FCALL                                                   'test'
         24        SEND_VAL                                                     'c'
         25        SEND_VAR                                                     !0
         26        SEND_VAR                                                     !1
         27        DO_FCALL                                          0  $10     
         28        SEND_VAR                                                     $10
         29        DO_ICALL                                             $11     
         30        CONCAT                                               ~12     $11, '%0A'
         31        FREE                                                         ~12
   28    32        INIT_FCALL                                                   'var_dump'
         33        INIT_FCALL                                                   'test'
         34        SEND_VAL                                                     ''
         35        SEND_VAR                                                     !0
         36        SEND_VAR                                                     !1
         37        DO_FCALL                                          0  $13     
         38        SEND_VAR                                                     $13
         39        DO_ICALL                                             $14     
         40        CONCAT                                               ~15     $14, '%0A'
         41        FREE                                                         ~15
   30    42        ECHO                                                         '-----%0A'
   32    43        INIT_FCALL                                                   'var_dump'
         44        INIT_FCALL                                                   'test2'
         45        SEND_VAL                                                     'a'
         46        SEND_VAR                                                     !0
         47        SEND_VAR                                                     !1
         48        DO_FCALL                                          0  $16     
         49        SEND_VAR                                                     $16
         50        DO_ICALL                                             $17     
         51        CONCAT                                               ~18     $17, '%0A'
         52        FREE                                                         ~18
   33    53        INIT_FCALL                                                   'var_dump'
         54        INIT_FCALL                                                   'test2'
         55        SEND_VAL                                                     'b'
         56        SEND_VAR                                                     !0
         57        SEND_VAR                                                     !1
         58        DO_FCALL                                          0  $19     
         59        SEND_VAR                                                     $19
         60        DO_ICALL                                             $20     
         61        CONCAT                                               ~21     $20, '%0A'
         62        FREE                                                         ~21
   34    63        INIT_FCALL                                                   'var_dump'
         64        INIT_FCALL                                                   'test2'
         65        SEND_VAL                                                     'c'
         66        SEND_VAR                                                     !0
         67        SEND_VAR                                                     !1
         68        DO_FCALL                                          0  $22     
         69        SEND_VAR                                                     $22
         70        DO_ICALL                                             $23     
         71        CONCAT                                               ~24     $23, '%0A'
         72        FREE                                                         ~24
   35    73        INIT_FCALL                                                   'var_dump'
         74        INIT_FCALL                                                   'test2'
         75        SEND_VAL                                                     ''
         76        SEND_VAR                                                     !0
         77        SEND_VAR                                                     !1
         78        DO_FCALL                                          0  $25     
         79        SEND_VAR                                                     $25
         80        DO_ICALL                                             $26     
         81        CONCAT                                               ~27     $26, '%0A'
         82        FREE                                                         ~27
   36    83      > RETURN                                                       1

Function test:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DVp4L
function name:  test
number of ops:  19
compiled vars:  !0 = $var, !1 = $G, !2 = $P, !3 = $value
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
    4     3        ISSET_ISEMPTY_CV                                             !0
          4      > JMPZ                                                         ~4, ->6
    5     5    > > RETURN                                                       null
    7     6    >   ISSET_ISEMPTY_DIM_OBJ                             0          !2, !0
          7      > JMPZ                                                         ~5, ->11
    8     8    >   FETCH_DIM_R                                          ~6      !2, !0
          9        ASSIGN                                                       !3, ~6
    7    10      > JMP                                                          ->17
    9    11    >   ISSET_ISEMPTY_DIM_OBJ                             0          !1, !0
         12      > JMPZ                                                         ~8, ->16
   10    13    >   FETCH_DIM_R                                          ~9      !1, !0
         14        ASSIGN                                                       !3, ~9
    9    15      > JMP                                                          ->17
   12    16    >   ASSIGN                                                       !3, null
   14    17    > > RETURN                                                       !3
   15    18*     > RETURN                                                       null

End of function test

Function test2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DVp4L
function name:  test2
number of ops:  11
compiled vars:  !0 = $var, !1 = $G, !2 = $P
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   17     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
   18     3        FETCH_DIM_IS                                         ~3      !2, !0
          4        COALESCE                                             ~4      ~3
          5        FETCH_DIM_IS                                         ~5      !1, !0
          6        COALESCE                                             ~6      ~5
          7        QM_ASSIGN                                            ~6      null
          8        QM_ASSIGN                                            ~4      ~6
          9      > RETURN                                                       ~4
   19    10*     > RETURN                                                       null

End of function test2

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
179.7 ms | 505 KiB | 15 Q