3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Example: SimpleXML tell apart a single element and a list of elements with a single element * * @link https://hakre.wordpress.com/2013/02/12/simplexml-type-cheatsheet/ * @libk http://stackoverflow.com/a/14829309/367456 */ $buffer = <<<XML <root> <result>the one childre</result> </root> XML; $xml = simplexml_load_string($buffer); /** * @param SimpleXMLElement $element */ function sxml_show_info(SimpleXMLElement $element) { $isSingleElement = $element[0] == $element; $isListOfElements = $element[0] != $element and $element->attributes() !== NULL; printf(" Is single-element? - %s\n", $isSingleElement ? 'Yes' : 'No'); printf(" Is list-of-elements? - %s\n", $isListOfElements ? 'Yes' : 'No'); } echo "For the single element:\n"; sxml_show_info($xml->result[0]); echo "\n"; echo "For the list of elements with a single item:\n"; sxml_show_info($xml->result); echo "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fttGI
function name:  (null)
number of ops:  19
compiled vars:  !0 = $buffer, !1 = $xml
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   ASSIGN                                                   !0, '%3Croot%3E%0A++++%3Cresult%3Ethe+one+childre%3C%2Fresult%3E%0A%3C%2Froot%3E'
   15     1        INIT_FCALL                                               'simplexml_load_string'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $3      
          4        ASSIGN                                                   !1, $3
   32     5        ECHO                                                     'For+the+single+element%3A%0A'
   33     6        INIT_FCALL                                               'sxml_show_info'
          7        FETCH_OBJ_R                                      ~5      !1, 'result'
          8        FETCH_DIM_R                                      ~6      ~5, 0
          9        SEND_VAL                                                 ~6
         10        DO_FCALL                                      0          
   34    11        ECHO                                                     '%0A'
   36    12        ECHO                                                     'For+the+list+of+elements+with+a+single+item%3A%0A'
   37    13        INIT_FCALL                                               'sxml_show_info'
         14        FETCH_OBJ_R                                      ~8      !1, 'result'
         15        SEND_VAL                                                 ~8
         16        DO_FCALL                                      0          
   38    17        ECHO                                                     '%0A'
         18      > RETURN                                                   1

Function sxml_show_info:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
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: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
Branch analysis from position: 25
Branch analysis from position: 12
filename:       /in/fttGI
function name:  sxml_show_info
number of ops:  29
compiled vars:  !0 = $element, !1 = $isSingleElement, !2 = $isListOfElements
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   23     1        FETCH_DIM_R                                      ~3      !0, 0
          2        IS_EQUAL                                         ~4      !0, ~3
          3        ASSIGN                                                   !1, ~4
   25     4        FETCH_DIM_R                                      ~6      !0, 0
          5        IS_NOT_EQUAL                                     ~7      !0, ~6
          6        ASSIGN                                           ~8      !2, ~7
          7      > JMPZ_EX                                          ~8      ~8, ->12
   26     8    >   INIT_METHOD_CALL                                         !0, 'attributes'
          9        DO_FCALL                                      0  $9      
         10        TYPE_CHECK                                  1020  ~10     $9
         11        BOOL                                             ~8      ~10
   28    12    >   INIT_FCALL                                               'printf'
         13        SEND_VAL                                                 '++Is+single-element%3F+++-+%25s%0A'
         14      > JMPZ                                                     !1, ->17
         15    >   QM_ASSIGN                                        ~11     'Yes'
         16      > JMP                                                      ->18
         17    >   QM_ASSIGN                                        ~11     'No'
         18    >   SEND_VAL                                                 ~11
         19        DO_ICALL                                                 
   29    20        INIT_FCALL                                               'printf'
         21        SEND_VAL                                                 '++Is+list-of-elements%3F+-+%25s%0A'
         22      > JMPZ                                                     !2, ->25
         23    >   QM_ASSIGN                                        ~13     'Yes'
         24      > JMP                                                      ->26
         25    >   QM_ASSIGN                                        ~13     'No'
         26    >   SEND_VAL                                                 ~13
         27        DO_ICALL                                                 
   30    28      > RETURN                                                   null

End of function sxml_show_info

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.94 ms | 1445 KiB | 17 Q