3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test extends ArrayIterator { public function __toString() { if (count($this) > 1) { return (string) $this->xml[0]; } return (string) $this->xml; } } 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; } return new Test((array)$this->xml->$offset); } 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'][0]; echo $xml['note']['recursive']['val'][1];
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EFAKp
function name:  (null)
number of ops:  18
compiled vars:  !0 = $str, !1 = $xml
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'test', 'arrayiterator'
   14     1        DECLARE_CLASS                                            'xmlarrayaccessiterator'
   63     2        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'
   76     3        NEW                                              $3      'XmlArrayAccessIterator'
          4        SEND_VAR_EX                                              !0
          5        SEND_VAL_EX                                              <false>
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $3
   78     8        FETCH_DIM_R                                      ~6      !1, 'note'
          9        FETCH_DIM_R                                      ~7      ~6, 'to'
         10        FETCH_DIM_R                                      ~8      ~7, 0
         11        ECHO                                                     ~8
   79    12        FETCH_DIM_R                                      ~9      !1, 'note'
         13        FETCH_DIM_R                                      ~10     ~9, 'recursive'
         14        FETCH_DIM_R                                      ~11     ~10, 'val'
         15        FETCH_DIM_R                                      ~12     ~11, 1
         16        ECHO                                                     ~12
         17      > RETURN                                                   1

Class Test:
Function __tostring:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EFAKp
function name:  __toString
number of ops:  15
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   FETCH_THIS                                       ~0      
          1        COUNT                                            ~1      ~0
          2        IS_SMALLER                                               1, ~1
          3      > JMPZ                                                     ~2, ->9
    8     4    >   FETCH_OBJ_R                                      ~3      'xml'
          5        FETCH_DIM_R                                      ~4      ~3, 0
          6        CAST                                          6  ~5      ~4
          7        VERIFY_RETURN_TYPE                                       ~5
          8      > RETURN                                                   ~5
   10     9    >   FETCH_OBJ_R                                      ~6      'xml'
         10        CAST                                          6  ~7      ~6
         11        VERIFY_RETURN_TYPE                                       ~7
         12      > RETURN                                                   ~7
   11    13*       VERIFY_RETURN_TYPE                                       
         14*     > RETURN                                                   null

End of function __tostring

End of class Test.

Class XmlArrayAccessIterator:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EFAKp
function name:  __construct
number of ops:  12
compiled vars:  !0 = $filePath, !1 = $isUrl
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <true>
   20     2        ASSIGN_OBJ                                               'isUrl'
          3        OP_DATA                                                  !1
   21     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
   22    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/EFAKp
function name:  offsetExists
number of ops:  7
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   26     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
   27     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
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EFAKp
function name:  offsetGet
number of ops:  16
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   31     1        FETCH_OBJ_R                                      ~1      'xml'
          2        INIT_METHOD_CALL                                         ~1, 'getName'
          3        DO_FCALL                                      0  $2      
          4        IS_EQUAL                                                 !0, $2
          5      > JMPZ                                                     ~3, ->8
   32     6    >   FETCH_THIS                                       ~4      
          7      > RETURN                                                   ~4
   35     8    >   NEW                                              $5      'Test'
          9        FETCH_OBJ_R                                      ~6      'xml'
         10        FETCH_OBJ_R                                      ~7      ~6, !0
         11        CAST                                          7  ~8      ~7
         12        SEND_VAL_EX                                              ~8
         13        DO_FCALL                                      0          
         14      > RETURN                                                   $5
   36    15*     > 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/EFAKp
function name:  __toString
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   FETCH_OBJ_R                                      ~0      'xml'
          1        CAST                                          6  ~1      ~0
          2        VERIFY_RETURN_TYPE                                       ~1
          3      > RETURN                                                   ~1
   41     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/EFAKp
function name:  offsetSet
number of ops:  13
compiled vars:  !0 = $offset, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   45     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
   46    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/EFAKp
function name:  offsetUnset
number of ops:  9
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   RECV                                             !0      
   50     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
   51     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/EFAKp
function name:  getIterator
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   FETCH_OBJ_R                                      ~0      'xml'
          1      > RETURN                                                   ~0
   56     2*     > RETURN                                                   null

End of function getiterator

End of class XmlArrayAccessIterator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.23 ms | 1407 KiB | 13 Q