3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { private $query; public function &findNode(array $path) { $link = &$this->query; foreach ($path as $element) { $link = &$link[$element]; } return $link; } public function setValues(array $path, array $values) { $node = &$this->findNode($path); $node = array_merge($node ?? [], $values); unset($node); return $this; } public function setValueByPath(array $path, $value): self { $link = &$this->findNode($path); if (is_array($value)) { $link[] = $value; } else { $link = $value; } unset($link); return $this; } public function print() { var_dump($this->query); } } $a = new A; $a ->setValues(['c', 'd'], [['test' => 1], ['test' => 2]]) ->setValues(['c', 'd'], [['test' => 3], ['test' => 4]]); $a ->setValueByPath(['a', 'b', 'c', 'd'], ['match' => 100500]) ->setValueByPath(['a', 'b', 'c', 'd'], ['match' => 1000]) ->setValueByPath(['a', 'b', 'c', 'd', 1, 'zzz'], 'lol'); print_r($a);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SofHF
function name:  (null)
number of ops:  27
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   NEW                                              $1      'A'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   48     3        INIT_METHOD_CALL                                         !0, 'setValues'
          4        SEND_VAL_EX                                              <array>
          5        SEND_VAL_EX                                              <array>
          6        DO_FCALL                                      0  $4      
   49     7        INIT_METHOD_CALL                                         $4, 'setValues'
          8        SEND_VAL_EX                                              <array>
          9        SEND_VAL_EX                                              <array>
         10        DO_FCALL                                      0          
   52    11        INIT_METHOD_CALL                                         !0, 'setValueByPath'
         12        SEND_VAL_EX                                              <array>
         13        SEND_VAL_EX                                              <array>
         14        DO_FCALL                                      0  $6      
   53    15        INIT_METHOD_CALL                                         $6, 'setValueByPath'
         16        SEND_VAL_EX                                              <array>
         17        SEND_VAL_EX                                              <array>
         18        DO_FCALL                                      0  $7      
   54    19        INIT_METHOD_CALL                                         $7, 'setValueByPath'
         20        SEND_VAL_EX                                              <array>
         21        SEND_VAL_EX                                              'lol'
         22        DO_FCALL                                      0          
   56    23        INIT_FCALL                                               'print_r'
         24        SEND_VAR                                                 !0
         25        DO_ICALL                                                 
         26      > RETURN                                                   1

Class A:
Function findnode:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 8
Return found
Branch analysis from position: 8
filename:       /in/SofHF
function name:  findNode
number of ops:  11
compiled vars:  !0 = $path, !1 = $link, !2 = $element
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    9     1        FETCH_OBJ_W                                      $3      'query'
          2        ASSIGN_REF                                               !1, $3
   10     3      > FE_RESET_R                                       $5      !0, ->8
          4    > > FE_FETCH_R                                               $5, !2, ->8
   11     5    >   FETCH_DIM_W                                      $6      !1, !2
          6        ASSIGN_REF                                               !1, $6
   10     7      > JMP                                                      ->4
          8    >   FE_FREE                                                  $5
   14     9      > RETURN_BY_REF                                            !1
   15    10*     > RETURN_BY_REF                                            null

End of function findnode

Function setvalues:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SofHF
function name:  setValues
number of ops:  17
compiled vars:  !0 = $path, !1 = $values, !2 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   19     2        INIT_METHOD_CALL                                         'findNode'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $3      
          5        ASSIGN_REF                                               !2, $3
   20     6        INIT_FCALL                                               'array_merge'
          7        COALESCE                                         ~5      !2
          8        QM_ASSIGN                                        ~5      <array>
          9        SEND_VAL                                                 ~5
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $6      
         12        ASSIGN                                                   !2, $6
   21    13        UNSET_CV                                                 !2
   23    14        FETCH_THIS                                       ~8      
         15      > RETURN                                                   ~8
   24    16*     > RETURN                                                   null

End of function setvalues

Function setvaluebypath:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SofHF
function name:  setValueByPath
number of ops:  18
compiled vars:  !0 = $path, !1 = $value, !2 = $link
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   28     2        INIT_METHOD_CALL                                         'findNode'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $3      
          5        ASSIGN_REF                                               !2, $3
   29     6        TYPE_CHECK                                  128          !1
          7      > JMPZ                                                     ~5, ->11
   30     8    >   ASSIGN_DIM                                               !2
          9        OP_DATA                                                  !1
         10      > JMP                                                      ->12
   32    11    >   ASSIGN                                                   !2, !1
   34    12    >   UNSET_CV                                                 !2
   36    13        FETCH_THIS                                       ~8      
         14        VERIFY_RETURN_TYPE                                       ~8
         15      > RETURN                                                   ~8
   37    16*       VERIFY_RETURN_TYPE                                       
         17*     > RETURN                                                   null

End of function setvaluebypath

Function print:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SofHF
function name:  print
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   INIT_FCALL                                               'var_dump'
          1        FETCH_OBJ_R                                      ~0      'query'
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                                 
   42     4      > RETURN                                                   null

End of function print

End of class A.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.49 ms | 1404 KiB | 19 Q