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"/> </entry> </feed>'; $xml = new SimpleXMLElement($buffer); echo "ibxml version: ", LIBXML_DOTTED_VERSION, "\n"; foreach ($xml->entry as $item) { //original comment: how to get seconds? $namespaces = $item->getNameSpaces(true); var_dump($namespaces); $yt = $item->children($namespaces['yt']); $seconds = $yt->duration->attributes(); echo $seconds['seconds'], "\n"; // original comment: but doesn't work. } $test = array("yt:second" => 124); var_dump($test); echo "done. should read 1870 one time.\n";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 32
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 32
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
filename:       /in/fKmjP
function name:  (null)
number of ops:  39
compiled vars:  !0 = $buffer, !1 = $xml, !2 = $item, !3 = $namespaces, !4 = $yt, !5 = $seconds, !6 = $test
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%2F%3E%0A++++%3C%2Fentry%3E%0A%3C%2Ffeed%3E'
   13     1        NEW                                              $8      'SimpleXMLElement'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $8
   15     5        ECHO                                                     'ibxml+version%3A+'
          6        ECHO                                                     '2.9.4'
          7        ECHO                                                     '%0A'
   17     8        FETCH_OBJ_R                                      ~11     !1, 'entry'
          9      > FE_RESET_R                                       $12     ~11, ->32
         10    > > FE_FETCH_R                                               $12, !2, ->32
   20    11    >   INIT_METHOD_CALL                                         !2, 'getNameSpaces'
         12        SEND_VAL_EX                                              <true>
         13        DO_FCALL                                      0  $13     
         14        ASSIGN                                                   !3, $13
   21    15        INIT_FCALL                                               'var_dump'
         16        SEND_VAR                                                 !3
         17        DO_ICALL                                                 
   22    18        INIT_METHOD_CALL                                         !2, 'children'
         19        CHECK_FUNC_ARG                                           
         20        FETCH_DIM_FUNC_ARG                               $16     !3, 'yt'
         21        SEND_FUNC_ARG                                            $16
         22        DO_FCALL                                      0  $17     
         23        ASSIGN                                                   !4, $17
   23    24        FETCH_OBJ_R                                      ~19     !4, 'duration'
         25        INIT_METHOD_CALL                                         ~19, 'attributes'
         26        DO_FCALL                                      0  $20     
         27        ASSIGN                                                   !5, $20
   25    28        FETCH_DIM_R                                      ~22     !5, 'seconds'
         29        ECHO                                                     ~22
         30        ECHO                                                     '%0A'
   17    31      > JMP                                                      ->10
         32    >   FE_FREE                                                  $12
   28    33        ASSIGN                                                   !6, <array>
   30    34        INIT_FCALL                                               'var_dump'
         35        SEND_VAR                                                 !6
         36        DO_ICALL                                                 
   32    37        ECHO                                                     'done.+should+read+1870+one+time.%0A'
         38      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.67 ms | 1400 KiB | 15 Q