3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml = '<?xml version="1.0" encoding="utf-8" ?> <soap-env> <person name="Max Musterman"> <car marke="BMW" kennung="i8"/> <phone name="iPhone">9</phone> <birth-place>Hamburg</birth-place> <address> <street>Hauptstraße 1</street> <plz>245698</plz> </address> </person> <person name="Dr. Dolittle"> <car marke="Audi" kennung="A3"/> <phone name="Sony">Xperia Z3</phone> <birth-place>München</birth-place> <address> <street>Partkstraße</street> <plz>365494</plz> </address> </person> </soap-env>'; $doc = new DomDocument('1.0', 'utf-8'); $doc->loadXml($xml); final class Hydrator { private $callbacks = []; public function __construct(array $callbacks = []) { $this->setCallbacks($callbacks); } public function setCallback(string $nodeName, callable $callback): void { $this->callbacks[$nodeName] = $callback; } public function setCallbacks(array $callbacks): void { foreach ($callbacks as $nodeName => $callback) { $this->setCallback($nodeName, $callback); } } public function hydrate(DOMNode $node) { $this->apply($node); if ($node->hasChildNodes()) { $this->traverseChildren($node); } } private function traverseChildren(DOMNode $node) { foreach ($node->childNodes as $child) { $this->hydrate($child); } } private function apply(DomNode $node) { if (array_key_exists($node->nodeName, $this->callbacks)) { print $callback($node, $this); } else { print $node->nodeName . PHP_EOL; } } } $hydrator = new Hydrator(); $hydrator->hydrate($doc->documentElement);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5Ovip
function name:  (null)
number of ops:  18
compiled vars:  !0 = $xml, !1 = $doc, !2 = $hydrator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3C%3Fxml+version%3D%221.0%22+encoding%3D%22utf-8%22+%3F%3E%0A%3Csoap-env%3E%0A++++%3Cperson+name%3D%22Max+Musterman%22%3E%0A++++++++%3Ccar+marke%3D%22BMW%22+kennung%3D%22i8%22%2F%3E%0A++++++++%3Cphone+name%3D%22iPhone%22%3E9%3C%2Fphone%3E%0A++++++++%3Cbirth-place%3EHamburg%3C%2Fbirth-place%3E%0A++++++++%3Caddress%3E%0A++++++++++++%3Cstreet%3EHauptstra%C3%9Fe+1%3C%2Fstreet%3E%0A++++++++++++%3Cplz%3E245698%3C%2Fplz%3E%0A++++++++%3C%2Faddress%3E%0A++++%3C%2Fperson%3E%0A++++%3Cperson+name%3D%22Dr.+Dolittle%22%3E%0A++++++++%3Ccar+marke%3D%22Audi%22+kennung%3D%22A3%22%2F%3E%0A++++++++%3Cphone+name%3D%22Sony%22%3EXperia+Z3%3C%2Fphone%3E%0A++++++++%3Cbirth-place%3EM%C3%BCnchen%3C%2Fbirth-place%3E%0A++++++++%3Caddress%3E%0A++++++++++++%3Cstreet%3EPartkstra%C3%9Fe%3C%2Fstreet%3E%0A++++++++++++%3Cplz%3E365494%3C%2Fplz%3E%0A++++++++%3C%2Faddress%3E%0A++++%3C%2Fperson%3E%0A%3C%2Fsoap-env%3E'
   25     1        NEW                                              $4      'DomDocument'
          2        SEND_VAL_EX                                              '1.0'
          3        SEND_VAL_EX                                              'utf-8'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $4
   26     6        INIT_METHOD_CALL                                         !1, 'loadXml'
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0          
   75     9        NEW                                              $8      'Hydrator'
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !2, $8
   76    12        INIT_METHOD_CALL                                         !2, 'hydrate'
         13        CHECK_FUNC_ARG                                           
         14        FETCH_OBJ_FUNC_ARG                               $11     !1, 'documentElement'
         15        SEND_FUNC_ARG                                            $11
         16        DO_FCALL                                      0          
         17      > RETURN                                                   1

Class Hydrator:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5Ovip
function name:  __construct
number of ops:  5
compiled vars:  !0 = $callbacks
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV_INIT                                        !0      <array>
   34     1        INIT_METHOD_CALL                                         'setCallbacks'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
   35     4      > RETURN                                                   null

End of function __construct

Function setcallback:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5Ovip
function name:  setCallback
number of ops:  6
compiled vars:  !0 = $nodeName, !1 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   39     2        FETCH_OBJ_W                                      $2      'callbacks'
          3        ASSIGN_DIM                                               $2, !0
          4        OP_DATA                                                  !1
   40     5      > RETURN                                                   null

End of function setcallback

Function setcallbacks:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 9
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/5Ovip
function name:  setCallbacks
number of ops:  11
compiled vars:  !0 = $callbacks, !1 = $callback, !2 = $nodeName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV                                             !0      
   44     1      > FE_RESET_R                                       $3      !0, ->9
          2    > > FE_FETCH_R                                       ~4      $3, !1, ->9
          3    >   ASSIGN                                                   !2, ~4
   45     4        INIT_METHOD_CALL                                         'setCallback'
          5        SEND_VAR_EX                                              !2
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0          
   44     8      > JMP                                                      ->2
          9    >   FE_FREE                                                  $3
   47    10      > RETURN                                                   null

End of function setcallbacks

Function hydrate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/5Ovip
function name:  hydrate
number of ops:  11
compiled vars:  !0 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   RECV                                             !0      
   51     1        INIT_METHOD_CALL                                         'apply'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
   53     4        INIT_METHOD_CALL                                         !0, 'hasChildNodes'
          5        DO_FCALL                                      0  $2      
          6      > JMPZ                                                     $2, ->10
   54     7    >   INIT_METHOD_CALL                                         'traverseChildren'
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0          
   56    10    > > RETURN                                                   null

End of function hydrate

Function traversechildren:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/5Ovip
function name:  traverseChildren
number of ops:  10
compiled vars:  !0 = $node, !1 = $child
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   RECV                                             !0      
   60     1        FETCH_OBJ_R                                      ~2      !0, 'childNodes'
          2      > FE_RESET_R                                       $3      ~2, ->8
          3    > > FE_FETCH_R                                               $3, !1, ->8
   61     4    >   INIT_METHOD_CALL                                         'hydrate'
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0          
   60     7      > JMP                                                      ->3
          8    >   FE_FREE                                                  $3
   63     9      > RETURN                                                   null

End of function traversechildren

Function apply:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5Ovip
function name:  apply
number of ops:  16
compiled vars:  !0 = $node, !1 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   RECV                                             !0      
   67     1        FETCH_OBJ_R                                      ~2      !0, 'nodeName'
          2        FETCH_OBJ_R                                      ~3      'callbacks'
          3        ARRAY_KEY_EXISTS                                         ~2, ~3
          4      > JMPZ                                                     ~4, ->12
   68     5    >   INIT_DYNAMIC_CALL                                        !1
          6        SEND_VAR_EX                                              !0
          7        FETCH_THIS                                       $5      
          8        SEND_VAR_EX                                              $5
          9        DO_FCALL                                      0  $6      
         10        ECHO                                                     $6
         11      > JMP                                                      ->15
   70    12    >   FETCH_OBJ_R                                      ~7      !0, 'nodeName'
         13        CONCAT                                           ~8      ~7, '%0A'
         14        ECHO                                                     ~8
   72    15    > > RETURN                                                   null

End of function apply

End of class Hydrator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.04 ms | 1394 KiB | 13 Q