3v4l.org

run code in 300+ PHP versions simultaneously
<?php class XmlArrayAccessIterator implements ArrayAccess, IteratorAggregate { private $xml; public function __construct($filePath, $isUrl = true) { $this->isUrl = $isUrl; $this->xml = new SimpleXmlIterator($filePath, 0, $isUrl); } public function offsetExists($offset) { return !is_null($this->xml->$offset); } public function offsetGet($offset) { if ($this->xml->getName() == $offset) { return $this; } if (preg_match('/(\w+)\[(\d+)\]/', $offset, $nodes)) { var_dump($this->xml->$nodes[1][1]->asXML()); return new self($this->xml->$nodes[1][$nodes[2]]->asXML(), false); } return new self($this->xml->$offset->asXML(), false); } public function __toString() { return (string) $this->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; } } $str = '<?xml version="1.0"?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don\'t forget me this weekend!</body> <recursive> <val>2</val> <val>4</val> </recursive> </note>'; $xml = new XmlArrayAccessIterator($str, false); //echo $xml['note']['to']; $xml['note']['recursive']['val[1]'];
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QWJ20
function name:  (null)
number of ops:  12
compiled vars:  !0 = $str, !1 = $xml
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'xmlarrayaccessiterator'
   56     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%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'
   68     2        NEW                                              $3      'XmlArrayAccessIterator'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAL_EX                                              <false>
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !1, $3
   72     7        FETCH_DIM_R                                      ~6      !1, 'note'
          8        FETCH_DIM_R                                      ~7      ~6, 'recursive'
          9        FETCH_DIM_R                                      ~8      ~7, 'val%5B1%5D'
         10        FREE                                                     ~8
         11      > RETURN                                                   1

Class XmlArrayAccessIterator:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QWJ20
function name:  __construct
number of ops:  12
compiled vars:  !0 = $filePath, !1 = $isUrl
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <true>
    9     2        ASSIGN_OBJ                                               'isUrl'
          3        OP_DATA                                                  !1
   10     4        NEW                                              $4      'SimpleXmlIterator'
          5        SEND_VAR_EX                                              !0
          6        SEND_VAL_EX                                              0
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0          
          9        ASSIGN_OBJ                                               'xml'
         10        OP_DATA                                                  $4
   11    11      > RETURN                                                   null

End of function __construct

Function offsetexists:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QWJ20
function name:  offsetExists
number of ops:  7
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   15     1        FETCH_OBJ_R                                      ~1      'xml'
          2        FETCH_OBJ_R                                      ~2      ~1, !0
          3        TYPE_CHECK                                    2  ~3      ~2
          4        BOOL_NOT                                         ~4      ~3
          5      > RETURN                                                   ~4
   16     6*     > 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 = 35
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QWJ20
function name:  offsetGet
number of ops:  45
compiled vars:  !0 = $offset, !1 = $nodes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   20     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
   21     6    >   FETCH_THIS                                       ~5      
          7      > RETURN                                                   ~5
   24     8    >   INIT_FCALL                                               'preg_match'
          9        SEND_VAL                                                 '%2F%28%5Cw%2B%29%5C%5B%28%5Cd%2B%29%5C%5D%2F'
         10        SEND_VAR                                                 !0
         11        SEND_REF                                                 !1
         12        DO_ICALL                                         $6      
         13      > JMPZ                                                     $6, ->35
   25    14    >   INIT_FCALL                                               'var_dump'
         15        FETCH_OBJ_R                                      ~7      'xml'
         16        FETCH_OBJ_R                                      ~8      ~7, !1
         17        FETCH_DIM_R                                      ~9      ~8, 1
         18        FETCH_DIM_R                                      ~10     ~9, 1
         19        INIT_METHOD_CALL                                         ~10, 'asXML'
         20        DO_FCALL                                      0  $11     
         21        SEND_VAR                                                 $11
         22        DO_ICALL                                                 
   26    23        NEW                          self                $13     
         24        FETCH_DIM_R                                      ~17     !1, 2
         25        FETCH_OBJ_R                                      ~14     'xml'
         26        FETCH_OBJ_R                                      ~15     ~14, !1
         27        FETCH_DIM_R                                      ~16     ~15, 1
         28        FETCH_DIM_R                                      ~18     ~16, ~17
         29        INIT_METHOD_CALL                                         ~18, 'asXML'
         30        DO_FCALL                                      0  $19     
         31        SEND_VAR_NO_REF_EX                                       $19
         32        SEND_VAL_EX                                              <false>
         33        DO_FCALL                                      0          
         34      > RETURN                                                   $13
   29    35    >   NEW                          self                $21     
         36        FETCH_OBJ_R                                      ~22     'xml'
         37        FETCH_OBJ_R                                      ~23     ~22, !0
         38        INIT_METHOD_CALL                                         ~23, 'asXML'
         39        DO_FCALL                                      0  $24     
         40        SEND_VAR_NO_REF_EX                                       $24
         41        SEND_VAL_EX                                              <false>
         42        DO_FCALL                                      0          
         43      > RETURN                                                   $21
   30    44*     > RETURN                                                   null

End of function offsetget

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

End of function __tostring

Function offsetset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/QWJ20
function name:  offsetSet
number of ops:  13
compiled vars:  !0 = $offset, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   39     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
   40    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/QWJ20
function name:  offsetUnset
number of ops:  9
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV                                             !0      
   44     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
   45     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/QWJ20
function name:  getIterator
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   FETCH_OBJ_R                                      ~0      'xml'
          1      > RETURN                                                   ~0
   50     2*     > RETURN                                                   null

End of function getiterator

End of class XmlArrayAccessIterator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.09 ms | 1408 KiB | 17 Q