3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(E_ALL); class XML { var $parser; #a reference to the XML parser var $document; #the entire XML structure built up so far var $current; #a pointer to the current item - what is this var $parent; #a pointer to the current parent - the parent will be an array var $parents; #an array of the most recent parent at each level var $last_opened_tag; function XML($data=null){ $this->parser = xml_parser_create(); xml_parser_set_option ($this->parser, XML_OPTION_CASE_FOLDING, 0); xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, "open", "close"); xml_set_character_data_handler($this->parser, "data"); # register_shutdown_function(array(&$this, 'destruct')); } function destruct(){ xml_parser_free($this->parser); } function parse($data){ $this->document = array(); $this->parent = &$this->document; $this->parents = array(); $this->last_opened_tag = NULL; xml_parse($this->parser, $data); return $this->document; } function open($parser, $tag, $attributes){ #echo "Opening tag $tag<br>\n"; $this->data = ""; $this->last_opened_tag = $tag; #tag is a string if(array_key_exists($tag, $this->parent)){ #echo "There's already an instance of '$tag' at the current level ($level)<br>\n"; if(is_array($this->parent[$tag]) and array_key_exists(0, $this->parent[$tag])){ #if the keys are numeric #need to make sure they're numeric (account for attributes) $key = count_numeric_items($this->parent[$tag]); #echo "There are $key instances: the keys are numeric.<br>\n"; }else{ #echo "There is only one instance. Shifting everything around<br>\n"; $temp = &$this->parent[$tag]; unset($this->parent[$tag]); $this->parent[$tag][0] = &$temp; if(array_key_exists("$tag attr", $this->parent)){ #shift the attributes around too if they exist $temp = &$this->parent["$tag attr"]; unset($this->parent["$tag attr"]); $this->parent[$tag]["0 attr"] = &$temp; } $key = 1; } $this->parent = &$this->parent[$tag]; }else{ $key = $tag; } if($attributes){ $this->parent["$key attr"] = $attributes; } $this->parent[$key] = array(); $this->parent = &$this->parent[$key]; $x = &$this->parent; array_unshift($this->parents, $x); } function data($parser, $data){ #echo "Data is '", htmlspecialchars($data), "'<br>\n"; if($this->last_opened_tag != NULL){ $this->data .= $data; } } function close($parser, $tag){ #echo "Close tag $tag<br>\n"; if($this->last_opened_tag == $tag){ $this->parent = $this->data; $this->last_opened_tag = NULL; } array_shift($this->parents); $this->parent = &$this->parents[0]; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vli9r
function name:  (null)
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 32767
          2        DO_ICALL                                                 
   89     3      > RETURN                                                   1

Class XML:
Function xml:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vli9r
function name:  XML
number of ops:  29
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV_INIT                                        !0      null
   13     1        INIT_FCALL                                               'xml_parser_create'
          2        DO_ICALL                                         $2      
          3        ASSIGN_OBJ                                               'parser'
          4        OP_DATA                                                  $2
   15     5        INIT_FCALL                                               'xml_parser_set_option'
          6        FETCH_OBJ_R                                      ~3      'parser'
          7        SEND_VAL                                                 ~3
          8        SEND_VAL                                                 1
          9        SEND_VAL                                                 0
         10        DO_ICALL                                                 
   16    11        INIT_FCALL                                               'xml_set_object'
         12        FETCH_OBJ_R                                      ~5      'parser'
         13        SEND_VAL                                                 ~5
         14        FETCH_THIS                                       ~6      
         15        SEND_VAL                                                 ~6
         16        DO_ICALL                                                 
   17    17        INIT_FCALL                                               'xml_set_element_handler'
         18        FETCH_OBJ_R                                      ~8      'parser'
         19        SEND_VAL                                                 ~8
         20        SEND_VAL                                                 'open'
         21        SEND_VAL                                                 'close'
         22        DO_ICALL                                                 
   18    23        INIT_FCALL                                               'xml_set_character_data_handler'
         24        FETCH_OBJ_R                                      ~10     'parser'
         25        SEND_VAL                                                 ~10
         26        SEND_VAL                                                 'data'
         27        DO_ICALL                                                 
   20    28      > RETURN                                                   null

End of function xml

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

End of function destruct

Function parse:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vli9r
function name:  parse
number of ops:  19
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   27     1        ASSIGN_OBJ                                               'document'
          2        OP_DATA                                                  <array>
   28     3        FETCH_OBJ_W                                      $3      'document'
          4        MAKE_REF                                         $4      $3
          5        ASSIGN_OBJ_REF                                           'parent'
          6        OP_DATA                                                  $4
   29     7        ASSIGN_OBJ                                               'parents'
          8        OP_DATA                                                  <array>
   30     9        ASSIGN_OBJ                                               'last_opened_tag'
         10        OP_DATA                                                  null
   31    11        INIT_FCALL                                               'xml_parse'
         12        FETCH_OBJ_R                                      ~7      'parser'
         13        SEND_VAL                                                 ~7
         14        SEND_VAR                                                 !0
         15        DO_ICALL                                                 
   32    16        FETCH_OBJ_R                                      ~9      'document'
         17      > RETURN                                                   ~9
   33    18*     > RETURN                                                   null

End of function parse

Function open:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 61
Branch analysis from position: 10
2 jumps found. (Code = 46) Position 1 = 14, Position 2 = 18
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 27
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 62
Branch analysis from position: 62
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 68
Branch analysis from position: 63
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 68
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 54
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 62
Branch analysis from position: 62
Branch analysis from position: 54
Branch analysis from position: 18
Branch analysis from position: 61
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 68
Branch analysis from position: 63
Branch analysis from position: 68
filename:       /in/vli9r
function name:  open
number of ops:  84
compiled vars:  !0 = $parser, !1 = $tag, !2 = $attributes, !3 = $key, !4 = $temp, !5 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   37     3        ASSIGN_OBJ                                               'data'
          4        OP_DATA                                                  ''
   38     5        ASSIGN_OBJ                                               'last_opened_tag'
          6        OP_DATA                                                  !1
   39     7        FETCH_OBJ_R                                      ~8      'parent'
          8        ARRAY_KEY_EXISTS                                         !1, ~8
          9      > JMPZ                                                     ~9, ->61
   41    10    >   FETCH_OBJ_R                                      ~10     'parent'
         11        FETCH_DIM_R                                      ~11     ~10, !1
         12        TYPE_CHECK                                  128  ~12     ~11
         13      > JMPZ_EX                                          ~12     ~12, ->18
         14    >   FETCH_OBJ_R                                      ~13     'parent'
         15        FETCH_DIM_R                                      ~14     ~13, !1
         16        ARRAY_KEY_EXISTS                                 ~15     0, ~14
         17        BOOL                                             ~12     ~15
         18    > > JMPZ                                                     ~12, ->27
   43    19    >   INIT_FCALL_BY_NAME                                       'count_numeric_items'
         20        CHECK_FUNC_ARG                                           
         21        FETCH_OBJ_FUNC_ARG                               $16     'parent'
         22        FETCH_DIM_FUNC_ARG                               $17     $16, !1
         23        SEND_FUNC_ARG                                            $17
         24        DO_FCALL                                      0  $18     
         25        ASSIGN                                                   !3, $18
         26      > JMP                                                      ->55
   47    27    >   FETCH_OBJ_W                                      $20     'parent'
         28        FETCH_DIM_W                                      $21     $20, !1
         29        ASSIGN_REF                                               !4, $21
   48    30        FETCH_OBJ_UNSET                                  $23     'parent'
         31        UNSET_DIM                                                $23, !1
   49    32        FETCH_OBJ_W                                      $24     'parent'
         33        FETCH_DIM_W                                      $25     $24, !1
         34        FETCH_DIM_W                                      $26     $25, 0
         35        ASSIGN_REF                                               $26, !4
   51    36        NOP                                                      
         37        FAST_CONCAT                                      ~28     !1, '+attr'
         38        FETCH_OBJ_R                                      ~29     'parent'
         39        ARRAY_KEY_EXISTS                                         ~28, ~29
         40      > JMPZ                                                     ~30, ->54
   53    41    >   NOP                                                      
         42        FAST_CONCAT                                      ~32     !1, '+attr'
         43        FETCH_OBJ_W                                      $31     'parent'
         44        FETCH_DIM_W                                      $33     $31, ~32
         45        ASSIGN_REF                                               !4, $33
   54    46        NOP                                                      
         47        FAST_CONCAT                                      ~36     !1, '+attr'
         48        FETCH_OBJ_UNSET                                  $35     'parent'
         49        UNSET_DIM                                                $35, ~36
   55    50        FETCH_OBJ_W                                      $37     'parent'
         51        FETCH_DIM_W                                      $38     $37, !1
         52        FETCH_DIM_W                                      $39     $38, '0+attr'
         53        ASSIGN_REF                                               $39, !4
   57    54    >   ASSIGN                                                   !3, 1
   59    55    >   FETCH_OBJ_W                                      $43     'parent'
         56        FETCH_DIM_W                                      $44     $43, !1
         57        MAKE_REF                                         $45     $44
         58        ASSIGN_OBJ_REF                                           'parent'
         59        OP_DATA                                                  $45
         60      > JMP                                                      ->62
   61    61    >   ASSIGN                                                   !3, !1
   63    62    > > JMPZ                                                     !2, ->68
   64    63    >   NOP                                                      
         64        FAST_CONCAT                                      ~48     !3, '+attr'
         65        FETCH_OBJ_W                                      $47     'parent'
         66        ASSIGN_DIM                                               $47, ~48
         67        OP_DATA                                                  !2
   67    68    >   FETCH_OBJ_W                                      $50     'parent'
         69        ASSIGN_DIM                                               $50, !3
         70        OP_DATA                                                  <array>
   68    71        FETCH_OBJ_W                                      $53     'parent'
         72        FETCH_DIM_W                                      $54     $53, !3
         73        MAKE_REF                                         $55     $54
         74        ASSIGN_OBJ_REF                                           'parent'
         75        OP_DATA                                                  $55
   69    76        FETCH_OBJ_W                                      $56     'parent'
         77        ASSIGN_REF                                               !5, $56
   70    78        INIT_FCALL                                               'array_unshift'
         79        FETCH_OBJ_W                                      $58     'parents'
         80        SEND_REF                                                 $58
         81        SEND_VAR                                                 !5
         82        DO_ICALL                                                 
   71    83      > RETURN                                                   null

End of function open

Function data:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/vli9r
function name:  data
number of ops:  8
compiled vars:  !0 = $parser, !1 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   73     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   75     2        FETCH_OBJ_R                                      ~2      'last_opened_tag'
          3        IS_NOT_EQUAL                                             ~2, null
          4      > JMPZ                                                     ~3, ->7
   76     5    >   ASSIGN_OBJ_OP                                 8          'data'
          6        OP_DATA                                                  !1
   78     7    > > RETURN                                                   null

End of function data

Function close:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/vli9r
function name:  close
number of ops:  20
compiled vars:  !0 = $parser, !1 = $tag
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   80     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   82     2        FETCH_OBJ_R                                      ~2      'last_opened_tag'
          3        IS_EQUAL                                                 !1, ~2
          4      > JMPZ                                                     ~3, ->10
   83     5    >   FETCH_OBJ_R                                      ~5      'data'
          6        ASSIGN_OBJ                                               'parent'
          7        OP_DATA                                                  ~5
   84     8        ASSIGN_OBJ                                               'last_opened_tag'
          9        OP_DATA                                                  null
   86    10    >   INIT_FCALL                                               'array_shift'
         11        FETCH_OBJ_W                                      $7      'parents'
         12        SEND_REF                                                 $7
         13        DO_ICALL                                                 
   87    14        FETCH_OBJ_W                                      $10     'parents'
         15        FETCH_DIM_W                                      $11     $10, 0
         16        MAKE_REF                                         $12     $11
         17        ASSIGN_OBJ_REF                                           'parent'
         18        OP_DATA                                                  $12
   88    19      > RETURN                                                   null

End of function close

End of class XML.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
209.4 ms | 1417 KiB | 33 Q