3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Parser { // main public static function parse($xmlData) { $res = null; libxml_use_internal_errors(true); $dom = new DOMDocument(); $dom->recover = true; if(!$dom->loadXML($xmlData)) { $res['error'] = libxml_get_errors(); libxml_clear_errors(); } else { self::read($res, $dom); } return $res; } // tools // TODO use alternate class private static function parseText($str) { return trim(htmlentities($str)); } // void private static function read(&$res, &$dom) { $rss = $dom->getElementsByTagName('rss'); if($rss->length == 0) { $res['error'] = 'No rss node.'; } else { $channel = $rss->item(0)->getElementsByTagName('channel'); if($channel->length == 0) { $res['error'] = 'No channel node.'; } else { self::getNodes($res, $channel, array('title', 'link', 'description')); } } } private static function getNode(&$res, &$channel, $name) { $node = $channel->item(0)->getElementsByTagName($name); if($node->length == 0) { $res[$name] = null; } else { $res[$name] = self::parseText($node->item(0)->nodeValue); } } private static function getNodes(&$res, &$channel, $names) { foreach($names as $name) { self::getNode($res, $channel, $name); } } } $file = file_get_contents('https://secure.php.net/feed.atom'); if(!$file) { echo 'err cannot read file'; // TODO curl internet } else { $res = Parser::parse($file); var_dump($res); }
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 = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/P561P
function name:  (null)
number of ops:  16
compiled vars:  !0 = $file, !1 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   INIT_FCALL                                               'file_get_contents'
          1        SEND_VAL                                                 'https%3A%2F%2Fsecure.php.net%2Ffeed.atom'
          2        DO_ICALL                                         $2      
          3        ASSIGN                                                   !0, $2
   55     4        BOOL_NOT                                         ~4      !0
          5      > JMPZ                                                     ~4, ->8
   56     6    >   ECHO                                                     'err+cannot+read+file'
          7      > JMP                                                      ->15
   58     8    >   INIT_STATIC_METHOD_CALL                                  'Parser', 'parse'
          9        SEND_VAR                                                 !0
         10        DO_FCALL                                      0  $5      
         11        ASSIGN                                                   !1, $5
   59    12        INIT_FCALL                                               'var_dump'
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                                 
   60    15    > > RETURN                                                   1

Class Parser:
Function parse:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 22
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/P561P
function name:  parse
number of ops:  28
compiled vars:  !0 = $xmlData, !1 = $res, !2 = $dom
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, null
    6     2        INIT_FCALL                                               'libxml_use_internal_errors'
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                                 
    7     5        NEW                                              $5      'DOMDocument'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !2, $5
    8     8        ASSIGN_OBJ                                               !2, 'recover'
          9        OP_DATA                                                  <true>
    9    10        INIT_METHOD_CALL                                         !2, 'loadXML'
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0  $9      
         13        BOOL_NOT                                         ~10     $9
         14      > JMPZ                                                     ~10, ->22
   10    15    >   INIT_FCALL                                               'libxml_get_errors'
         16        DO_ICALL                                         $12     
         17        ASSIGN_DIM                                               !1, 'error'
         18        OP_DATA                                                  $12
   11    19        INIT_FCALL                                               'libxml_clear_errors'
         20        DO_ICALL                                                 
         21      > JMP                                                      ->26
   13    22    >   INIT_STATIC_METHOD_CALL                                  'read'
         23        SEND_VAR_EX                                              !1
         24        SEND_VAR_EX                                              !2
         25        DO_FCALL                                      0          
   15    26    > > RETURN                                                   !1
   16    27*     > RETURN                                                   null

End of function parse

Function parsetext:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/P561P
function name:  parseText
number of ops:  9
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     1        INIT_FCALL                                               'trim'
          2        INIT_FCALL                                               'htmlentities'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5        SEND_VAR                                                 $1
          6        DO_ICALL                                         $2      
          7      > RETURN                                                   $2
   21     8*     > RETURN                                                   null

End of function parsetext

Function read:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 12
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 25
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/P561P
function name:  read
number of ops:  31
compiled vars:  !0 = $res, !1 = $dom, !2 = $rss, !3 = $channel
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   25     2        INIT_METHOD_CALL                                         !1, 'getElementsByTagName'
          3        SEND_VAL_EX                                              'rss'
          4        DO_FCALL                                      0  $4      
          5        ASSIGN                                                   !2, $4
   26     6        FETCH_OBJ_R                                      ~6      !2, 'length'
          7        IS_EQUAL                                                 ~6, 0
          8      > JMPZ                                                     ~7, ->12
   27     9    >   ASSIGN_DIM                                               !0, 'error'
         10        OP_DATA                                                  'No+rss+node.'
         11      > JMP                                                      ->30
   29    12    >   INIT_METHOD_CALL                                         !2, 'item'
         13        SEND_VAL_EX                                              0
         14        DO_FCALL                                      0  $9      
         15        INIT_METHOD_CALL                                         $9, 'getElementsByTagName'
         16        SEND_VAL_EX                                              'channel'
         17        DO_FCALL                                      0  $10     
         18        ASSIGN                                                   !3, $10
   30    19        FETCH_OBJ_R                                      ~12     !3, 'length'
         20        IS_EQUAL                                                 ~12, 0
         21      > JMPZ                                                     ~13, ->25
   31    22    >   ASSIGN_DIM                                               !0, 'error'
         23        OP_DATA                                                  'No+channel+node.'
         24      > JMP                                                      ->30
   33    25    >   INIT_STATIC_METHOD_CALL                                  'getNodes'
         26        SEND_VAR_EX                                              !0
         27        SEND_VAR_EX                                              !3
         28        SEND_VAL_EX                                              <array>
         29        DO_FCALL                                      0          
   36    30    > > RETURN                                                   null

End of function read

Function getnode:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/P561P
function name:  getNode
number of ops:  26
compiled vars:  !0 = $res, !1 = $channel, !2 = $name, !3 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   39     3        INIT_METHOD_CALL                                         !1, 'item'
          4        SEND_VAL_EX                                              0
          5        DO_FCALL                                      0  $4      
          6        INIT_METHOD_CALL                                         $4, 'getElementsByTagName'
          7        SEND_VAR_EX                                              !2
          8        DO_FCALL                                      0  $5      
          9        ASSIGN                                                   !3, $5
   40    10        FETCH_OBJ_R                                      ~7      !3, 'length'
         11        IS_EQUAL                                                 ~7, 0
         12      > JMPZ                                                     ~8, ->16
   41    13    >   ASSIGN_DIM                                               !0, !2
         14        OP_DATA                                                  null
         15      > JMP                                                      ->25
   43    16    >   INIT_STATIC_METHOD_CALL                                  'parseText'
         17        INIT_METHOD_CALL                                         !3, 'item'
         18        SEND_VAL_EX                                              0
         19        DO_FCALL                                      0  $11     
         20        FETCH_OBJ_R                                      ~12     $11, 'nodeValue'
         21        SEND_VAL                                                 ~12
         22        DO_FCALL                                      0  $13     
         23        ASSIGN_DIM                                               !0, !2
         24        OP_DATA                                                  $13
   45    25    > > RETURN                                                   null

End of function getnode

Function getnodes:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/P561P
function name:  getNodes
number of ops:  13
compiled vars:  !0 = $res, !1 = $channel, !2 = $names, !3 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   48     3      > FE_RESET_R                                       $4      !2, ->11
          4    > > FE_FETCH_R                                               $4, !3, ->11
   49     5    >   INIT_STATIC_METHOD_CALL                                  'getNode'
          6        SEND_REF                                                 !0
          7        SEND_REF                                                 !1
          8        SEND_VAR                                                 !3
          9        DO_FCALL                                      0          
   48    10      > JMP                                                      ->4
         11    >   FE_FREE                                                  $4
   51    12      > RETURN                                                   null

End of function getnodes

End of class Parser.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
180.7 ms | 1408 KiB | 27 Q