3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * SimpleXMLElement Introspection */ error_reporting(~0); $xml = '<document> <child> give <grandchild a1="v1" a2="v2"> me </grandchild> <grandchild> more </grandchild> sugar. </child> <child> </child> <single/> </document> '; $simple = new SimpleXMLElement($xml); /** * @param SimpleXMLElement $element * @return mixed */ function simplexml_get_documentelement(SimpleXMLElement $element) { foreach($element as $element) break; list($documentElement) = $element->xpath('/*'); return $documentElement; } $documentElement = $simple; $attributeList = $simple->child->grandchild->attributes(); $attributeListEmpty = $simple->child->attributes(); $attribute = $simple->child->grandchild['a1']; $suite = array( 'get_documentelement' => array('simplexml_get_documentelement', array( array($documentElement, $documentElement), array($documentElement, $documentElement->child), array($documentElement, $documentElement->single), array($documentElement, $simple->xpath('/*')[0]), array($documentElement, $simple->simple->xpath('/*')[0]), array($documentElement, $documentElement->child[0]), array($documentElement, $documentElement->child->grandchild), array($documentElement, $attribute), array($documentElement, $attributeList), array(NULL, $attributeListEmpty), )), ); echo "Running tests with LIBXML ", LIBXML_DOTTED_VERSION, ":\n"; run_test_suite($suite); function run_test_suite(array $testsuite) { foreach ($testsuite as $caselabel => $testcasedef) { list($callback, $testcase) = $testcasedef; $stats[] = run_testcase($testcase, $callback, $caselabel); } echo "\n"; $stat['tests'] = 0; $stat['failures'] = 0; foreach ($stats as $singled) { $stat['tests'] += $singled['tests']; $stat['failures'] += $singled['failures']; echo $singled['messages']; } printf("Done %d tests with %d failures.", $stat['tests'], $stat['failures']); } function run_testcase(array $testcase, $callback, $label = null) { if ($label === null) $label = $callback; $stats['tests'] = 0; $stats['failures'] = 0; $messages = ''; foreach ($testcase as $i => $test) { list($expected, $subject, $testlabel) = $test + array(2 => "#$i"); $labeltest = $label . ' ' . $testlabel; ob_start(); $result = run_test($expected, $subject, $callback, $labeltest); $buffer = ob_get_clean(); echo $result ? '.' : 'F'; if ($buffer) { $messages .= sprintf("### %s ###\n", $labeltest); $messages .= $buffer; } $stats['tests']++; if (!$result) $stats['failures']++; } return $stats + array('messages' => $messages); } function run_test($expected, $subject, $callback, $label) { $actual = call_user_func($callback, $subject); if ($expected instanceof SimpleXMLElement and $actual instanceof SimpleXMLElement) { $result = $actual == $expected; } else { $result = $actual === $expected; } if (!$result) { $extra = ''; if ($subject instanceof SimpleXMLElement) { $extra = sprintf(' with %s', rtrim($subject->asXML())); } printf("FAILED to test %s%s.\n", $label, $extra); echo 'expected: ', var_dump($expected); echo 'actual:', var_dump($actual); } return $result; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jX5tM
function name:  (null)
number of ops:  78
compiled vars:  !0 = $xml, !1 = $simple, !2 = $documentElement, !3 = $attributeList, !4 = $attributeListEmpty, !5 = $attribute, !6 = $suite
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 -1
          2        DO_ICALL                                                 
    8     3        ASSIGN                                                   !0, '%3Cdocument%3E%0A++++%3Cchild%3E%0A++++++++give%0A++++++++%3Cgrandchild+a1%3D%22v1%22+a2%3D%22v2%22%3E%0A++++++++++++me%0A++++++++%3C%2Fgrandchild%3E%0A++++++++%3Cgrandchild%3E%0A++++++++++++more%0A++++++++%3C%2Fgrandchild%3E%0A++++++++sugar.%0A++++%3C%2Fchild%3E%0A++++%3Cchild%3E%0A++++%3C%2Fchild%3E%0A++++%3Csingle%2F%3E%0A%3C%2Fdocument%3E%0A'
   25     4        NEW                                              $9      'SimpleXMLElement'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $9
   39     8        ASSIGN                                                   !2, !1
   40     9        FETCH_OBJ_R                                      ~13     !1, 'child'
         10        FETCH_OBJ_R                                      ~14     ~13, 'grandchild'
         11        INIT_METHOD_CALL                                         ~14, 'attributes'
         12        DO_FCALL                                      0  $15     
         13        ASSIGN                                                   !3, $15
   41    14        FETCH_OBJ_R                                      ~17     !1, 'child'
         15        INIT_METHOD_CALL                                         ~17, 'attributes'
         16        DO_FCALL                                      0  $18     
         17        ASSIGN                                                   !4, $18
   42    18        FETCH_OBJ_R                                      ~20     !1, 'child'
         19        FETCH_OBJ_R                                      ~21     ~20, 'grandchild'
         20        FETCH_DIM_R                                      ~22     ~21, 'a1'
         21        ASSIGN                                                   !5, ~22
   46    22        INIT_ARRAY                                       ~24     'simplexml_get_documentelement'
   47    23        INIT_ARRAY                                       ~25     !2
         24        ADD_ARRAY_ELEMENT                                ~25     !2
         25        INIT_ARRAY                                       ~26     ~25
   48    26        INIT_ARRAY                                       ~27     !2
         27        FETCH_OBJ_R                                      ~28     !2, 'child'
         28        ADD_ARRAY_ELEMENT                                ~27     ~28
         29        ADD_ARRAY_ELEMENT                                ~26     ~27
   49    30        INIT_ARRAY                                       ~29     !2
         31        FETCH_OBJ_R                                      ~30     !2, 'single'
         32        ADD_ARRAY_ELEMENT                                ~29     ~30
         33        ADD_ARRAY_ELEMENT                                ~26     ~29
   50    34        INIT_ARRAY                                       ~31     !2
         35        INIT_METHOD_CALL                                         !1, 'xpath'
         36        SEND_VAL_EX                                              '%2F%2A'
         37        DO_FCALL                                      0  $32     
         38        FETCH_DIM_R                                      ~33     $32, 0
         39        ADD_ARRAY_ELEMENT                                ~31     ~33
         40        ADD_ARRAY_ELEMENT                                ~26     ~31
   51    41        INIT_ARRAY                                       ~34     !2
         42        FETCH_OBJ_R                                      ~35     !1, 'simple'
         43        INIT_METHOD_CALL                                         ~35, 'xpath'
         44        SEND_VAL_EX                                              '%2F%2A'
         45        DO_FCALL                                      0  $36     
         46        FETCH_DIM_R                                      ~37     $36, 0
         47        ADD_ARRAY_ELEMENT                                ~34     ~37
         48        ADD_ARRAY_ELEMENT                                ~26     ~34
   52    49        INIT_ARRAY                                       ~38     !2
         50        FETCH_OBJ_R                                      ~39     !2, 'child'
         51        FETCH_DIM_R                                      ~40     ~39, 0
         52        ADD_ARRAY_ELEMENT                                ~38     ~40
         53        ADD_ARRAY_ELEMENT                                ~26     ~38
   53    54        INIT_ARRAY                                       ~41     !2
         55        FETCH_OBJ_R                                      ~42     !2, 'child'
         56        FETCH_OBJ_R                                      ~43     ~42, 'grandchild'
         57        ADD_ARRAY_ELEMENT                                ~41     ~43
         58        ADD_ARRAY_ELEMENT                                ~26     ~41
   54    59        INIT_ARRAY                                       ~44     !2
         60        ADD_ARRAY_ELEMENT                                ~44     !5
         61        ADD_ARRAY_ELEMENT                                ~26     ~44
   55    62        INIT_ARRAY                                       ~45     !2
         63        ADD_ARRAY_ELEMENT                                ~45     !3
         64        ADD_ARRAY_ELEMENT                                ~26     ~45
   46    65        INIT_ARRAY                                       ~46     null
   56    66        ADD_ARRAY_ELEMENT                                ~46     !4
         67        ADD_ARRAY_ELEMENT                                ~26     ~46
         68        ADD_ARRAY_ELEMENT                                ~24     ~26
         69        INIT_ARRAY                                       ~47     ~24, 'get_documentelement'
   45    70        ASSIGN                                                   !6, ~47
   60    71        ECHO                                                     'Running+tests+with+LIBXML+'
         72        ECHO                                                     '2.9.4'
         73        ECHO                                                     '%3A%0A'
   61    74        INIT_FCALL_BY_NAME                                       'run_test_suite'
         75        SEND_VAR_EX                                              !6
         76        DO_FCALL                                      0          
  131    77      > RETURN                                                   1

Function simplexml_get_documentelement:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 5
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
Branch analysis from position: 5
filename:       /in/jX5tM
function name:  simplexml_get_documentelement
number of ops:  14
compiled vars:  !0 = $element, !1 = $documentElement
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   33     1      > FE_RESET_R                                       $2      !0, ->5
          2    > > FE_FETCH_R                                               $2, !0, ->5
          3    > > JMP                                                      ->5
          4*       JMP                                                      ->2
          5    >   FE_FREE                                                  $2
   34     6        INIT_METHOD_CALL                                         !0, 'xpath'
          7        SEND_VAL_EX                                              '%2F%2A'
          8        DO_FCALL                                      0  $3      
          9        FETCH_LIST_R                                     $4      $3, 0
         10        ASSIGN                                                   !1, $4
         11        FREE                                                     $3
   35    12      > RETURN                                                   !1
   36    13*     > RETURN                                                   null

End of function simplexml_get_documentelement

Function run_test_suite:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 18
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 18
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 18
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 35
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 35
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
Branch analysis from position: 18
filename:       /in/jX5tM
function name:  run_test_suite
number of ops:  44
compiled vars:  !0 = $testsuite, !1 = $testcasedef, !2 = $caselabel, !3 = $callback, !4 = $testcase, !5 = $stats, !6 = $stat, !7 = $singled
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   RECV                                             !0      
   66     1      > FE_RESET_R                                       $8      !0, ->18
          2    > > FE_FETCH_R                                       ~9      $8, !1, ->18
          3    >   ASSIGN                                                   !2, ~9
   67     4        QM_ASSIGN                                        ~11     !1
          5        FETCH_LIST_R                                     $12     ~11, 0
          6        ASSIGN                                                   !3, $12
          7        FETCH_LIST_R                                     $14     ~11, 1
          8        ASSIGN                                                   !4, $14
          9        FREE                                                     ~11
   68    10        INIT_FCALL_BY_NAME                                       'run_testcase'
         11        SEND_VAR_EX                                              !4
         12        SEND_VAR_EX                                              !3
         13        SEND_VAR_EX                                              !2
         14        DO_FCALL                                      0  $17     
         15        ASSIGN_DIM                                               !5
         16        OP_DATA                                                  $17
   66    17      > JMP                                                      ->2
         18    >   FE_FREE                                                  $8
   70    19        ECHO                                                     '%0A'
   72    20        ASSIGN_DIM                                               !6, 'tests'
         21        OP_DATA                                                  0
   73    22        ASSIGN_DIM                                               !6, 'failures'
         23        OP_DATA                                                  0
   75    24      > FE_RESET_R                                       $20     !5, ->35
         25    > > FE_FETCH_R                                               $20, !7, ->35
   76    26    >   FETCH_DIM_R                                      ~22     !7, 'tests'
         27        ASSIGN_DIM_OP                +=               1          !6, 'tests'
         28        OP_DATA                                                  ~22
   77    29        FETCH_DIM_R                                      ~24     !7, 'failures'
         30        ASSIGN_DIM_OP                +=               1          !6, 'failures'
         31        OP_DATA                                                  ~24
   78    32        FETCH_DIM_R                                      ~25     !7, 'messages'
         33        ECHO                                                     ~25
   75    34      > JMP                                                      ->25
         35    >   FE_FREE                                                  $20
   81    36        INIT_FCALL                                               'printf'
         37        SEND_VAL                                                 'Done+%25d+tests+with+%25d+failures.'
         38        FETCH_DIM_R                                      ~26     !6, 'tests'
         39        SEND_VAL                                                 ~26
         40        FETCH_DIM_R                                      ~27     !6, 'failures'
         41        SEND_VAL                                                 ~27
         42        DO_ICALL                                                 
   82    43      > RETURN                                                   null

End of function run_test_suite

Function run_testcase:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 59
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 59
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 43
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 52
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 58
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 58
Branch analysis from position: 52
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 52
Branch analysis from position: 46
Branch analysis from position: 52
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 59
Branch analysis from position: 6
filename:       /in/jX5tM
function name:  run_testcase
number of ops:  64
compiled vars:  !0 = $testcase, !1 = $callback, !2 = $label, !3 = $stats, !4 = $messages, !5 = $test, !6 = $i, !7 = $expected, !8 = $subject, !9 = $testlabel, !10 = $labeltest, !11 = $result, !12 = $buffer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   84     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
   86     3        TYPE_CHECK                                    2          !2
          4      > JMPZ                                                     ~13, ->6
          5    >   ASSIGN                                                   !2, !1
   88     6    >   ASSIGN_DIM                                               !3, 'tests'
          7        OP_DATA                                                  0
   89     8        ASSIGN_DIM                                               !3, 'failures'
          9        OP_DATA                                                  0
   91    10        ASSIGN                                                   !4, ''
   93    11      > FE_RESET_R                                       $18     !0, ->59
         12    > > FE_FETCH_R                                       ~19     $18, !5, ->59
         13    >   ASSIGN                                                   !6, ~19
   94    14        NOP                                                      
         15        FAST_CONCAT                                      ~21     '%23', !6
         16        INIT_ARRAY                                       ~22     ~21, 2
         17        ADD                                              ~23     !5, ~22
         18        FETCH_LIST_R                                     $24     ~23, 0
         19        ASSIGN                                                   !7, $24
         20        FETCH_LIST_R                                     $26     ~23, 1
         21        ASSIGN                                                   !8, $26
         22        FETCH_LIST_R                                     $28     ~23, 2
         23        ASSIGN                                                   !9, $28
         24        FREE                                                     ~23
   95    25        CONCAT                                           ~30     !2, '+'
         26        CONCAT                                           ~31     ~30, !9
         27        ASSIGN                                                   !10, ~31
   96    28        INIT_FCALL                                               'ob_start'
         29        DO_ICALL                                                 
   97    30        INIT_FCALL_BY_NAME                                       'run_test'
         31        SEND_VAR_EX                                              !7
         32        SEND_VAR_EX                                              !8
         33        SEND_VAR_EX                                              !1
         34        SEND_VAR_EX                                              !10
         35        DO_FCALL                                      0  $34     
         36        ASSIGN                                                   !11, $34
   98    37        INIT_FCALL                                               'ob_get_clean'
         38        DO_ICALL                                         $36     
         39        ASSIGN                                                   !12, $36
   99    40      > JMPZ                                                     !11, ->43
         41    >   QM_ASSIGN                                        ~38     '.'
         42      > JMP                                                      ->44
         43    >   QM_ASSIGN                                        ~38     'F'
         44    >   ECHO                                                     ~38
  100    45      > JMPZ                                                     !12, ->52
  101    46    >   INIT_FCALL                                               'sprintf'
         47        SEND_VAL                                                 '%23%23%23+%25s+%23%23%23%0A'
         48        SEND_VAR                                                 !10
         49        DO_ICALL                                         $39     
         50        ASSIGN_OP                                     8          !4, $39
  102    51        ASSIGN_OP                                     8          !4, !12
  105    52    >   FETCH_DIM_RW                                     $42     !3, 'tests'
         53        PRE_INC                                                  $42
  106    54        BOOL_NOT                                         ~44     !11
         55      > JMPZ                                                     ~44, ->58
         56    >   FETCH_DIM_RW                                     $45     !3, 'failures'
         57        PRE_INC                                                  $45
   93    58    > > JMP                                                      ->12
         59    >   FE_FREE                                                  $18
  109    60        INIT_ARRAY                                       ~47     !4, 'messages'
         61        ADD                                              ~48     !3, ~47
         62      > RETURN                                                   ~48
  110    63*     > RETURN                                                   null

End of function run_testcase

Function run_test:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 48
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 33
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
Branch analysis from position: 48
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 48
Branch analysis from position: 20
Branch analysis from position: 48
Branch analysis from position: 12
filename:       /in/jX5tM
function name:  run_test
number of ops:  50
compiled vars:  !0 = $expected, !1 = $subject, !2 = $callback, !3 = $label, !4 = $actual, !5 = $result, !6 = $extra
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  112     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
  114     4        INIT_USER_CALL                                1          'call_user_func', !2
          5        SEND_USER                                                !1
          6        DO_FCALL                                      0  $7      
          7        ASSIGN                                                   !4, $7
  115     8        INSTANCEOF                                       ~9      !0, 'SimpleXMLElement'
          9      > JMPZ_EX                                          ~9      ~9, ->12
         10    >   INSTANCEOF                                       ~10     !4, 'SimpleXMLElement'
         11        BOOL                                             ~9      ~10
         12    > > JMPZ                                                     ~9, ->16
  116    13    >   IS_EQUAL                                         ~11     !4, !0
         14        ASSIGN                                                   !5, ~11
         15      > JMP                                                      ->18
  118    16    >   IS_IDENTICAL                                     ~13     !4, !0
         17        ASSIGN                                                   !5, ~13
  121    18    >   BOOL_NOT                                         ~15     !5
         19      > JMPZ                                                     ~15, ->48
  122    20    >   ASSIGN                                                   !6, ''
  123    21        INSTANCEOF                                               !1, 'SimpleXMLElement'
         22      > JMPZ                                                     ~17, ->33
  124    23    >   INIT_FCALL                                               'sprintf'
         24        SEND_VAL                                                 '+with+%25s'
         25        INIT_FCALL                                               'rtrim'
         26        INIT_METHOD_CALL                                         !1, 'asXML'
         27        DO_FCALL                                      0  $18     
         28        SEND_VAR                                                 $18
         29        DO_ICALL                                         $19     
         30        SEND_VAR                                                 $19
         31        DO_ICALL                                         $20     
         32        ASSIGN                                                   !6, $20
  126    33    >   INIT_FCALL                                               'printf'
         34        SEND_VAL                                                 'FAILED+to+test+%25s%25s.%0A'
         35        SEND_VAR                                                 !3
         36        SEND_VAR                                                 !6
         37        DO_ICALL                                                 
  127    38        ECHO                                                     'expected%3A+'
         39        INIT_FCALL                                               'var_dump'
         40        SEND_VAR                                                 !0
         41        DO_ICALL                                         $23     
         42        ECHO                                                     $23
  128    43        ECHO                                                     'actual%3A'
         44        INIT_FCALL                                               'var_dump'
         45        SEND_VAR                                                 !4
         46        DO_ICALL                                         $24     
         47        ECHO                                                     $24
  130    48    > > RETURN                                                   !5
  131    49*     > RETURN                                                   null

End of function run_test

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.58 ms | 1412 KiB | 27 Q