3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyXML extends SimpleXMLElement { public function firstChild() { $children = $this->children(); foreach ($children as $child) break; return $child; } public function keyHasTwins($key) { if (isset($this->$key)) return (count($this->$key)>1); else return false; } public function hasChildren() { return (bool)count($this->children()); } public function nodeIsCollection() { return count($this); } public function getChildrenKeys() { $all = []; $children = $this->children(); foreach ($children as $key => $child) { if (!in_array($key, $all)) $all[] = $key; } return $all; } } $s = '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>'. '<request>'. ' <body>'. ' <rows>'. ' <row id="1"/>'. ' <row id="2"/>'. ' <row id="3"/>'. ' <row2 ver="2.0">test data</row2>'. ' <row2 ver="2.1">test data 2</row2>'. ' <row3 ver="3.0">'. ' <test inherit="yes">data</test>'. ' </row3>'. ' <row4 ver="4.0">my test data</row4>'. ' </rows>'. ' </body>'. '</request>'; $obj = new MyXML($s); $row = $obj->firstChild()->firstChild()->row4; var_dump($row);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oOALg
function name:  (null)
number of ops:  15
compiled vars:  !0 = $s, !1 = $obj, !2 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   ASSIGN                                                   !0, '%3C%3Fxml+version%3D%221.0%22+encoding%3D%22utf-8%22+standalone%3D%22yes%22+%3F%3E%3Crequest%3E++%3Cbody%3E++++++%3Crows%3E++++++++++%3Crow+id%3D%221%22%2F%3E++++++++++%3Crow+id%3D%222%22%2F%3E++++++++++%3Crow+id%3D%223%22%2F%3E++++++++++%3Crow2+ver%3D%222.0%22%3Etest+data%3C%2Frow2%3E%09%09%09%3Crow2+ver%3D%222.1%22%3Etest+data+2%3C%2Frow2%3E%09%09%09%3Crow3+ver%3D%223.0%22%3E%09%09%09%09%3Ctest+inherit%3D%22yes%22%3Edata%3C%2Ftest%3E%09%09%09%3C%2Frow3%3E++++++++++%3Crow4+ver%3D%224.0%22%3Emy+test+data%3C%2Frow4%3E++++++%3C%2Frows%3E++%3C%2Fbody%3E%3C%2Frequest%3E'
   62     1        NEW                                              $4      'MyXML'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $4
   64     5        INIT_METHOD_CALL                                         !1, 'firstChild'
          6        DO_FCALL                                      0  $7      
          7        INIT_METHOD_CALL                                         $7, 'firstChild'
          8        DO_FCALL                                      0  $8      
          9        FETCH_OBJ_R                                      ~9      $8, 'row4'
         10        ASSIGN                                                   !2, ~9
   66    11        INIT_FCALL                                               'var_dump'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                                 
         14      > RETURN                                                   1

Class MyXML:
Function firstchild:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
Branch analysis from position: 7
filename:       /in/oOALg
function name:  firstChild
number of ops:  10
compiled vars:  !0 = $children, !1 = $child
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   INIT_METHOD_CALL                                         'children'
          1        DO_FCALL                                      0  $2      
          2        ASSIGN                                                   !0, $2
    7     3      > FE_RESET_R                                       $4      !0, ->7
          4    > > FE_FETCH_R                                               $4, !1, ->7
    8     5    > > JMP                                                      ->7
    7     6*       JMP                                                      ->4
          7    >   FE_FREE                                                  $4
    9     8      > RETURN                                                   !1
   10     9*     > RETURN                                                   null

End of function firstchild

Function keyhastwins:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oOALg
function name:  keyHasTwins
number of ops:  10
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   14     1        ISSET_ISEMPTY_PROP_OBJ                                   !0
          2      > JMPZ                                                     ~1, ->8
   15     3    >   FETCH_OBJ_R                                      ~2      !0
          4        COUNT                                            ~3      ~2
          5        IS_SMALLER                                       ~4      1, ~3
          6      > RETURN                                                   ~4
          7*       JMP                                                      ->9
   17     8    > > RETURN                                                   <false>
   18     9*     > RETURN                                                   null

End of function keyhastwins

Function haschildren:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oOALg
function name:  hasChildren
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   INIT_METHOD_CALL                                         'children'
          1        DO_FCALL                                      0  $0      
          2        COUNT                                            ~1      $0
          3        BOOL                                             ~2      ~1
          4      > RETURN                                                   ~2
   23     5*     > RETURN                                                   null

End of function haschildren

Function nodeiscollection:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oOALg
function name:  nodeIsCollection
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   FETCH_THIS                                       ~0      
          1        COUNT                                            ~1      ~0
          2      > RETURN                                                   ~1
   28     3*     > RETURN                                                   null

End of function nodeiscollection

Function getchildrenkeys:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 16
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 16
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 15
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 15
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/oOALg
function name:  getChildrenKeys
number of ops:  19
compiled vars:  !0 = $all, !1 = $children, !2 = $child, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   ASSIGN                                                   !0, <array>
   33     1        INIT_METHOD_CALL                                         'children'
          2        DO_FCALL                                      0  $5      
          3        ASSIGN                                                   !1, $5
   35     4      > FE_RESET_R                                       $7      !1, ->16
          5    > > FE_FETCH_R                                       ~8      $7, !2, ->16
          6    >   ASSIGN                                                   !3, ~8
   36     7        INIT_FCALL                                               'in_array'
          8        SEND_VAR                                                 !3
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $10     
         11        BOOL_NOT                                         ~11     $10
         12      > JMPZ                                                     ~11, ->15
   37    13    >   ASSIGN_DIM                                               !0
         14        OP_DATA                                                  !3
   35    15    > > JMP                                                      ->5
         16    >   FE_FREE                                                  $7
   40    17      > RETURN                                                   !0
   41    18*     > RETURN                                                   null

End of function getchildrenkeys

End of class MyXML.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.04 ms | 1396 KiB | 17 Q