3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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($nodes); 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
Jump found. Position 1 = -2
filename:       /in/S0h4g
function name:  (null)
number of ops:  15
compiled vars:  !0 = $str, !1 = $xml
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   DECLARE_CLASS                                    $2      '%00xmlarrayaccessiterator%2Fin%2FS0h4g0x7f0e55c38488', 'xmlarrayaccessiterator'
         1        ADD_INTERFACE                                            $2, 'ArrayAccess'
         2        ADD_INTERFACE                                            $2, 'IteratorAggregate'
         3        VERIFY_ABSTRACT_CLASS                                    $2
  66     4        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     5        NEW                                              $4      :1
         6        SEND_VAR_EX                                              !0
         7        SEND_VAL_EX                                              <false>
         8        DO_FCALL                                      0          
         9        ASSIGN                                                   !1, $4
  72    10        FETCH_DIM_R                                      $7      !1, 'note'
        11        FETCH_DIM_R                                      $8      $7, 'recursive'
        12        FETCH_DIM_R                                      $9      $8, 'val%5B1%5D'
        13        FREE                                                     $9
        14      > RETURN                                                   1

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

End of function offsetget

Function __tostring:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/S0h4g
function name:  __toString
number of ops:  4
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      > RETURN                                                   ~1
  35     3*     > RETURN                                                   null

End of function __tostring

Function offsetset:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/S0h4g
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      :-6
         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
Jump found. Position 1 = -2
filename:       /in/S0h4g
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      :-6
         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
Jump found. Position 1 = -2
filename:       /in/S0h4g
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 7.1.0