3v4l.org

run code in 300+ PHP versions simultaneously
<?php class XmlArrayAccessIterator implements ArrayAccess, IteratorAggregate { const ATTRIBUTE_PREFIX = '@'; private $xml; public function __construct(SimpleXmlIterator $xml) { $this->xml = $xml; } private function getElement($offset) { $isAttribute = false; if (substr($offset, 0, 1) == self::ATTRIBUTE_PREFIX) { $offset = substr($offset, 1); $isAttribute = false; } if (false !== $this->xml->$offset->asXML() && !$isAttribute) { $xml = $this->xml->$offset; } else { $xml = $this->xml[$offset]; } return $xml; } public function offsetExists($offset) { return !is_null($this->getElement($offset)); } public function offsetGet($offset) { if ($this->xml->getName() == $offset) { return $this; } $xml = $this->getElement($offset); if (is_null($xml)) { throw new RuntimeException('unknown node or attribute "' . $offset . '"'); } return new self($xml); } public function offsetSet($offset, $value) { throw new RuntimeException('This is readonly. writing to "' . (string) $offset . '" with value "' . (string) $value . '" not possible'); } public function offsetUnset($offset) { throw new RuntimeException('This is readonly. Unsetting "' . (string) $offset . '" not possible'); } public function getIterator() { return $this->xml; } public function __toString() { return (string) $this->xml; } } $xml = '<?xml version="1.0"?> <note> <to>Tove</to> <from>Jani</from> <heading foo="bar">Reminder</heading> <body>Don\'t forget me this weekend!</body> <recursive> <val>2</val> <val>4</val> </recursive> </note>'; $simple = new SimpleXmlIterator($xml); $xml = new XmlArrayAccessIterator($simple); echo $xml['note']['to']; echo $xml['note']['recursive']['val'][1]; echo $xml['note']['heading']['@foo']; echo $xml['note']['heading']['foo'];
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0Askm
function name:  (null)
number of ops:  27
compiled vars:  !0 = $xml, !1 = $simple
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'xmlarrayaccessiterator'
   77     1        ASSIGN                                                   !0, '%3C%3Fxml+version%3D%221.0%22%3F%3E%0A%3Cnote%3E%0A++++%3Cto%3ETove%3C%2Fto%3E%0A++++%3Cfrom%3EJani%3C%2Ffrom%3E%0A++++%3Cheading+foo%3D%22bar%22%3EReminder%3C%2Fheading%3E%0A++++%3Cbody%3EDon%27t+forget+me+this+weekend%21%3C%2Fbody%3E%0A%09%3Crecursive%3E%0A%09%09%3Cval%3E2%3C%2Fval%3E%0A%09%09%3Cval%3E4%3C%2Fval%3E%0A%09%3C%2Frecursive%3E%0A%3C%2Fnote%3E'
   88     2        NEW                                              $3      'SimpleXmlIterator'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $3
   90     6        NEW                                              $6      'XmlArrayAccessIterator'
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !0, $6
   92    10        FETCH_DIM_R                                      ~9      !0, 'note'
         11        FETCH_DIM_R                                      ~10     ~9, 'to'
         12        ECHO                                                     ~10
   93    13        FETCH_DIM_R                                      ~11     !0, 'note'
         14        FETCH_DIM_R                                      ~12     ~11, 'recursive'
         15        FETCH_DIM_R                                      ~13     ~12, 'val'
         16        FETCH_DIM_R                                      ~14     ~13, 1
         17        ECHO                                                     ~14
   94    18        FETCH_DIM_R                                      ~15     !0, 'note'
         19        FETCH_DIM_R                                      ~16     ~15, 'heading'
         20        FETCH_DIM_R                                      ~17     ~16, '%40foo'
         21        ECHO                                                     ~17
   95    22        FETCH_DIM_R                                      ~18     !0, 'note'
         23        FETCH_DIM_R                                      ~19     ~18, 'heading'
         24        FETCH_DIM_R                                      ~20     ~19, 'foo'
         25        ECHO                                                     ~20
         26      > RETURN                                                   1

Class XmlArrayAccessIterator:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0Askm
function name:  __construct
number of ops:  4
compiled vars:  !0 = $xml
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   11     1        ASSIGN_OBJ                                               'xml'
          2        OP_DATA                                                  !0
   12     3      > RETURN                                                   null

End of function __construct

Function getelement:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
2 jumps found. (Code = 46) Position 1 = 21, Position 2 = 23
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 28
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
Branch analysis from position: 15
filename:       /in/0Askm
function name:  getElement
number of ops:  33
compiled vars:  !0 = $offset, !1 = $isAttribute, !2 = $xml
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   16     1        ASSIGN                                                   !1, <false>
   17     2        INIT_FCALL                                               'substr'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 0
          5        SEND_VAL                                                 1
          6        DO_ICALL                                         $4      
          7        IS_EQUAL                                                 $4, '%40'
          8      > JMPZ                                                     ~5, ->15
   18     9    >   INIT_FCALL                                               'substr'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 1
         12        DO_ICALL                                         $6      
         13        ASSIGN                                                   !0, $6
   19    14        ASSIGN                                                   !1, <false>
   22    15    >   FETCH_OBJ_R                                      ~9      'xml'
         16        FETCH_OBJ_R                                      ~10     ~9, !0
         17        INIT_METHOD_CALL                                         ~10, 'asXML'
         18        DO_FCALL                                      0  $11     
         19        TYPE_CHECK                                  1018  ~12     $11
         20      > JMPZ_EX                                          ~12     ~12, ->23
         21    >   BOOL_NOT                                         ~13     !1
         22        BOOL                                             ~12     ~13
         23    > > JMPZ                                                     ~12, ->28
   23    24    >   FETCH_OBJ_R                                      ~14     'xml'
         25        FETCH_OBJ_R                                      ~15     ~14, !0
         26        ASSIGN                                                   !2, ~15
         27      > JMP                                                      ->31
   26    28    >   FETCH_OBJ_R                                      ~17     'xml'
         29        FETCH_DIM_R                                      ~18     ~17, !0
         30        ASSIGN                                                   !2, ~18
   29    31    > > RETURN                                                   !2
   30    32*     > RETURN                                                   null

End of function getelement

Function offsetexists:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0Askm
function name:  offsetExists
number of ops:  8
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
   34     1        INIT_METHOD_CALL                                         'getElement'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $1      
          4        TYPE_CHECK                                    2  ~2      $1
          5        BOOL_NOT                                         ~3      ~2
          6      > RETURN                                                   ~3
   35     7*     > RETURN                                                   null

End of function offsetexists

Function offsetget:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 20
Branch analysis from position: 14
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0Askm
function name:  offsetGet
number of ops:  25
compiled vars:  !0 = $offset, !1 = $xml
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
   39     1        FETCH_OBJ_R                                      ~2      'xml'
          2        INIT_METHOD_CALL                                         ~2, 'getName'
          3        DO_FCALL                                      0  $3      
          4        IS_EQUAL                                                 !0, $3
          5      > JMPZ                                                     ~4, ->8
   40     6    >   FETCH_THIS                                       ~5      
          7      > RETURN                                                   ~5
   43     8    >   INIT_METHOD_CALL                                         'getElement'
          9        SEND_VAR                                                 !0
         10        DO_FCALL                                      0  $6      
         11        ASSIGN                                                   !1, $6
   45    12        TYPE_CHECK                                    2          !1
         13      > JMPZ                                                     ~8, ->20
   46    14    >   NEW                                              $9      'RuntimeException'
         15        CONCAT                                           ~10     'unknown+node+or+attribute+%22', !0
         16        CONCAT                                           ~11     ~10, '%22'
         17        SEND_VAL_EX                                              ~11
         18        DO_FCALL                                      0          
         19      > THROW                                         0          $9
   49    20    >   NEW                          self                $13     
         21        SEND_VAR_EX                                              !1
         22        DO_FCALL                                      0          
         23      > RETURN                                                   $13
   50    24*     > RETURN                                                   null

End of function offsetget

Function offsetset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/0Askm
function name:  offsetSet
number of ops:  13
compiled vars:  !0 = $offset, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   54     2        NEW                                              $2      'RuntimeException'
          3        CAST                                          6  ~3      !0
          4        CONCAT                                           ~4      'This+is+readonly.+writing+to+%22', ~3
          5        CONCAT                                           ~5      ~4, '%22+with+value+%22'
          6        CAST                                          6  ~6      !1
          7        CONCAT                                           ~7      ~5, ~6
          8        CONCAT                                           ~8      ~7, '%22+not+possible'
          9        SEND_VAL_EX                                              ~8
         10        DO_FCALL                                      0          
         11      > THROW                                         0          $2
   55    12*     > RETURN                                                   null

End of function offsetset

Function offsetunset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/0Askm
function name:  offsetUnset
number of ops:  9
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   RECV                                             !0      
   59     1        NEW                                              $1      'RuntimeException'
          2        CAST                                          6  ~2      !0
          3        CONCAT                                           ~3      'This+is+readonly.+Unsetting+%22', ~2
          4        CONCAT                                           ~4      ~3, '%22+not+possible'
          5        SEND_VAL_EX                                              ~4
          6        DO_FCALL                                      0          
          7      > THROW                                         0          $1
   60     8*     > RETURN                                                   null

End of function offsetunset

Function getiterator:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0Askm
function name:  getIterator
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   FETCH_OBJ_R                                      ~0      'xml'
          1      > RETURN                                                   ~0
   65     2*     > RETURN                                                   null

End of function getiterator

Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0Askm
function name:  __toString
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   FETCH_OBJ_R                                      ~0      'xml'
          1        CAST                                          6  ~1      ~0
          2        VERIFY_RETURN_TYPE                                       ~1
          3      > RETURN                                                   ~1
   70     4*       VERIFY_RETURN_TYPE                                       
          5*     > RETURN                                                   null

End of function __tostring

End of class XmlArrayAccessIterator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.95 ms | 1400 KiB | 15 Q