3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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()); } } $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>'. ' </rows>'. ' </body>'. '</request>'; $obj = new MyXML($s); $rows = $obj->firstChild()->firstChild()->children(); var_dump($rows->hasChildren('row')); var_dump($rows->hasChildren('row2')); var_dump($rows->hasChildren('my-row'));
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/NQdcp
function name:  (null)
number of ops:  33
compiled vars:  !0 = $s, !1 = $obj, !2 = $rows
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   2     0  E >   NOP                                                      
         1        NOP                                                      
  38     2        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++++++%3C%2Frows%3E++%3C%2Fbody%3E%3C%2Frequest%3E'
  40     3        NEW                                              $6      :-3
         4        SEND_VAR_EX                                              !0
         5        DO_FCALL                                      0          
         6        ASSIGN                                                   !1, $6
  41     7        INIT_METHOD_CALL                                         !1, 'firstChild'
         8        DO_FCALL                                      0  $9      
         9        INIT_METHOD_CALL                                         $9, 'firstChild'
        10        DO_FCALL                                      0  $10     
        11        INIT_METHOD_CALL                                         $10, 'children'
        12        DO_FCALL                                      0  $11     
        13        ASSIGN                                                   !2, $11
  43    14        INIT_FCALL                                               'var_dump'
        15        INIT_METHOD_CALL                                         !2, 'hasChildren'
        16        SEND_VAL_EX                                              'row'
        17        DO_FCALL                                      0  $13     
        18        SEND_VAR                                                 $13
        19        DO_ICALL                                                 
  44    20        INIT_FCALL                                               'var_dump'
        21        INIT_METHOD_CALL                                         !2, 'hasChildren'
        22        SEND_VAL_EX                                              'row2'
        23        DO_FCALL                                      0  $15     
        24        SEND_VAR                                                 $15
        25        DO_ICALL                                                 
  45    26        INIT_FCALL                                               'var_dump'
        27        INIT_METHOD_CALL                                         !2, 'hasChildren'
        28        SEND_VAL_EX                                              'my-row'
        29        DO_FCALL                                      0  $17     
        30        SEND_VAR                                                 $17
        31        DO_ICALL                                                 
        32      > RETURN                                                   1

Class MyXML:
Function firstchild:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
Jump found. Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
Jump found. Position 1 = 7
Branch analysis from position: 7
Jump found. Position 1 = -2
Branch analysis from position: 7
Branch analysis from position: 7
filename:       /in/NQdcp
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
         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
Jump found. Position 1 = 3, Position 2 = 10
Branch analysis from position: 3
Jump found. Position 1 = -2
Branch analysis from position: 10
Jump found. Position 1 = -2
filename:       /in/NQdcp
function name:  keyHasTwins
number of ops:  12
compiled vars:  !0 = $key
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  12     0  E >   RECV                                             !0      
  14     1        ISSET_ISEMPTY_PROP_OBJ                           ~1      !0
         2      > JMPZ                                                     ~1, ->10
  15     3    >   INIT_FCALL                                               'count'
         4        FETCH_OBJ_R                                      $2      !0
         5        SEND_VAR                                                 $2
         6        DO_ICALL                                         $3      
         7        IS_SMALLER                                       ~4      1, $3
         8      > RETURN                                                   ~4
         9*       JMP                                                      ->11
  17    10    > > RETURN                                                   <false>
  18    11*     > RETURN                                                   null

End of function keyhastwins

Function haschildren:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/NQdcp
function name:  hasChildren
number of ops:  8
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  22     0  E >   INIT_FCALL                                               'count'
         1        INIT_METHOD_CALL                                         'children'
         2        DO_FCALL                                      0  $0      
         3        SEND_VAR                                                 $0
         4        DO_ICALL                                         $1      
         5        CAST                                         13  ~2      $1
         6      > RETURN                                                   ~2
  23     7*     > RETURN                                                   null

End of function haschildren

End of class MyXML.

Generated using Vulcan Logic Dumper, using php 7.2.0