3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * How to get attribute of node with namespace using SimpleXML? * * @link http://stackoverflow.com/q/6576773/367456 */ $buffer = '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:yt="http://gdata.youtube.com/schemas/2007"> <entry> <yt:duration seconds="1870" yt:seconds="0 in yt namespace" /> </entry> </feed>'; $xml = new SimpleXMLElement($buffer); if (!defined('LIBXML_DOTTED_VERSION')) { echo "PHP/LIBXML unsupported/too old."; return; } echo "ibxml version: ", LIBXML_DOTTED_VERSION, "\n"; $youtube = $xml; echo 'via attributes(): ', $youtube->entry->children('yt')->duration->attributes()->seconds, "\n"; echo 'via array-access: ', $youtube->entry->children('yt')->duration['seconds'], "\n"; echo 'via property : ', $youtube->entry->children('yt')->duration->seconds, "\n";
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/AWmO1
function name:  (null)
number of ops:  42
compiled vars:  !0 = $buffer, !1 = $xml, !2 = $youtube
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   ASSIGN                                                   !0, '%3Cfeed+xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2005%2FAtom%22+xmlns%3Ayt%3D%22http%3A%2F%2Fgdata.youtube.com%2Fschemas%2F2007%22%3E%0A++++%3Centry%3E%0A++++++++%3Cyt%3Aduration+seconds%3D%221870%22+yt%3Aseconds%3D%220+in+yt+namespace%22+%2F%3E%0A++++%3C%2Fentry%3E%0A%3C%2Ffeed%3E'
   13     1        NEW                                              $4      'SimpleXMLElement'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $4
   15     5      > JMPZ                                                     <false>, ->8
   16     6    >   ECHO                                                     'PHP%2FLIBXML+unsupported%2Ftoo+old.'
   17     7      > RETURN                                                   null
   20     8    >   ECHO                                                     'ibxml+version%3A+'
          9        ECHO                                                     '2.9.4'
         10        ECHO                                                     '%0A'
   22    11        ASSIGN                                                   !2, !1
   24    12        ECHO                                                     'via+attributes%28%29%3A+'
         13        FETCH_OBJ_R                                      ~8      !2, 'entry'
         14        INIT_METHOD_CALL                                         ~8, 'children'
         15        SEND_VAL_EX                                              'yt'
         16        DO_FCALL                                      0  $9      
         17        FETCH_OBJ_R                                      ~10     $9, 'duration'
         18        INIT_METHOD_CALL                                         ~10, 'attributes'
         19        DO_FCALL                                      0  $11     
         20        FETCH_OBJ_R                                      ~12     $11, 'seconds'
         21        ECHO                                                     ~12
         22        ECHO                                                     '%0A'
   25    23        ECHO                                                     'via+array-access%3A+'
         24        FETCH_OBJ_R                                      ~13     !2, 'entry'
         25        INIT_METHOD_CALL                                         ~13, 'children'
         26        SEND_VAL_EX                                              'yt'
         27        DO_FCALL                                      0  $14     
         28        FETCH_OBJ_R                                      ~15     $14, 'duration'
         29        FETCH_DIM_R                                      ~16     ~15, 'seconds'
         30        ECHO                                                     ~16
         31        ECHO                                                     '%0A'
   26    32        ECHO                                                     'via+property++++%3A+'
         33        FETCH_OBJ_R                                      ~17     !2, 'entry'
         34        INIT_METHOD_CALL                                         ~17, 'children'
         35        SEND_VAL_EX                                              'yt'
         36        DO_FCALL                                      0  $18     
         37        FETCH_OBJ_R                                      ~19     $18, 'duration'
         38        FETCH_OBJ_R                                      ~20     ~19, 'seconds'
         39        ECHO                                                     ~20
         40        ECHO                                                     '%0A'
         41      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.23 ms | 1399 KiB | 13 Q