3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Replaces elements from passed arrays into the first array * * array_replace() replaces the values of array1 with values having the * same keys in each of the following arrays. If a key from the first array * exists in the second array, its value will be replaced by the value from * the second array. If the key exists in the second array, and not the * first, it will be created in the first array. If a key only exists in * the first array, it will be left as is. If several arrays are passed for * replacement, they will be processed in order, the later arrays * overwriting the previous values. * * @since PHP 5.3.0 * @param array $array1 The array in which elements are replaced * @param array $array2... The array from which elements will be extracted * @return array Returns an array, or NULL if an error occurs */ function phpcompat_array_replace(array $array1, array $array2 = null) { $args = func_get_args(); $num_args = func_num_args(); if ($num_args < 1) { trigger_error( sprintf('array_replace() expects at least 1 parameter, %d given', $num_args), E_USER_WARNING ); return null; } $res = array(); for ($i = 0; $i < $num_args; ++$i) { if (is_array($args[$i])) { foreach ($args[$i] as $key => $val) { $res[$key] = $val; } } else { trigger_error( sprintf('array_replace(): Argument #%d is not an array', $i + 1), E_USER_WARNING ); return null; } } return $res; } var_dump(array_replace()); var_dump(phpcompat_array_replace());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kX30W
function name:  (null)
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'array_replace'
          2        DO_ICALL                                         $0      
          3        SEND_VAR                                                 $0
          4        DO_ICALL                                                 
   54     5        INIT_FCALL                                               'var_dump'
          6        INIT_FCALL                                               'phpcompat_array_replace'
          7        DO_FCALL                                      0  $2      
          8        SEND_VAR                                                 $2
          9        DO_ICALL                                                 
         10      > RETURN                                                   1

Function phpcompat_array_replace:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 20
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 32
Branch analysis from position: 23
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 30
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 30
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 20
Branch analysis from position: 45
Branch analysis from position: 20
Branch analysis from position: 30
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kX30W
function name:  phpcompat_array_replace
number of ops:  47
compiled vars:  !0 = $array1, !1 = $array2, !2 = $args, !3 = $num_args, !4 = $res, !5 = $i, !6 = $val, !7 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   23     2        FUNC_GET_ARGS                                    ~8      
          3        ASSIGN                                                   !2, ~8
   24     4        FUNC_NUM_ARGS                                    ~10     
          5        ASSIGN                                                   !3, ~10
   26     6        IS_SMALLER                                               !3, 1
          7      > JMPZ                                                     ~12, ->17
   27     8    >   INIT_FCALL                                               'trigger_error'
   28     9        INIT_FCALL                                               'sprintf'
         10        SEND_VAL                                                 'array_replace%28%29+expects+at+least+1+parameter%2C+%25d+given'
         11        SEND_VAR                                                 !3
         12        DO_ICALL                                         $13     
         13        SEND_VAR                                                 $13
   29    14        SEND_VAL                                                 512
         15        DO_ICALL                                                 
   31    16      > RETURN                                                   null
   34    17    >   ASSIGN                                                   !4, <array>
   35    18        ASSIGN                                                   !5, 0
         19      > JMP                                                      ->43
   36    20    >   FETCH_DIM_R                                      ~17     !2, !5
         21        TYPE_CHECK                                  128          ~17
         22      > JMPZ                                                     ~18, ->32
   37    23    >   FETCH_DIM_R                                      ~19     !2, !5
         24      > FE_RESET_R                                       $20     ~19, ->30
         25    > > FE_FETCH_R                                       ~21     $20, !6, ->30
         26    >   ASSIGN                                                   !7, ~21
   38    27        ASSIGN_DIM                                               !4, !7
         28        OP_DATA                                                  !6
   37    29      > JMP                                                      ->25
         30    >   FE_FREE                                                  $20
         31      > JMP                                                      ->42
   41    32    >   INIT_FCALL                                               'trigger_error'
   42    33        INIT_FCALL                                               'sprintf'
         34        SEND_VAL                                                 'array_replace%28%29%3A+Argument+%23%25d+is+not+an+array'
         35        ADD                                              ~24     !5, 1
         36        SEND_VAL                                                 ~24
         37        DO_ICALL                                         $25     
         38        SEND_VAR                                                 $25
   43    39        SEND_VAL                                                 512
         40        DO_ICALL                                                 
   45    41      > RETURN                                                   null
   35    42    >   PRE_INC                                                  !5
         43    >   IS_SMALLER                                               !5, !3
         44      > JMPNZ                                                    ~28, ->20
   49    45    > > RETURN                                                   !4
   50    46*     > RETURN                                                   null

End of function phpcompat_array_replace

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.27 ms | 1403 KiB | 22 Q