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> '; echo substr_count($xml, "\r"); return; $simple = new SimpleXMLElement($xml); /** * @param SimpleXMLElement $element * @return string */ function simplexml_get_xml_without_declaration(SimpleXMLElement $element) { list($elementNode) = $element->xpath('.'); list($documentElement) = $element->xpath('/*'); $xml = $element->asXML(); if ($elementNode == $element and $documentElement == $element) { list(, $xml) = explode("\n", $xml, 2); } return $xml; } $documentElement = $simple; $attributeList = $simple->child->grandchild->attributes(); $attributeListEmpty = $simple->child->attributes(); $attribute = $simple->child->grandchild['a1']; $suite = array( 'get_xml_nodecl' => array('simplexml_get_xml_without_declaration', array( array($xml, $simple), array($simple->child->asXML(), $simple->child), )), ); 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/PKAMV
function name:  (null)
number of ops:  49
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        INIT_FCALL                                               'substr_count'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 '%0D'
          7        DO_ICALL                                         $9      
          8        ECHO                                                     $9
   27     9      > RETURN                                                   null
   29    10*       NEW                                              $10     'SimpleXMLElement'
         11*       SEND_VAR_EX                                              !0
         12*       DO_FCALL                                      0          
         13*       ASSIGN                                                   !1, $10
   50    14*       ASSIGN                                                   !2, !1
   51    15*       FETCH_OBJ_R                                      ~14     !1, 'child'
         16*       FETCH_OBJ_R                                      ~15     ~14, 'grandchild'
         17*       INIT_METHOD_CALL                                         ~15, 'attributes'
         18*       DO_FCALL                                      0  $16     
         19*       ASSIGN                                                   !3, $16
   52    20*       FETCH_OBJ_R                                      ~18     !1, 'child'
         21*       INIT_METHOD_CALL                                         ~18, 'attributes'
         22*       DO_FCALL                                      0  $19     
         23*       ASSIGN                                                   !4, $19
   53    24*       FETCH_OBJ_R                                      ~21     !1, 'child'
         25*       FETCH_OBJ_R                                      ~22     ~21, 'grandchild'
         26*       FETCH_DIM_R                                      ~23     ~22, 'a1'
         27*       ASSIGN                                                   !5, ~23
   57    28*       INIT_ARRAY                                       ~25     'simplexml_get_xml_without_declaration'
   58    29*       INIT_ARRAY                                       ~26     !0
         30*       ADD_ARRAY_ELEMENT                                ~26     !1
         31*       INIT_ARRAY                                       ~27     ~26
   59    32*       FETCH_OBJ_R                                      ~28     !1, 'child'
         33*       INIT_METHOD_CALL                                         ~28, 'asXML'
         34*       DO_FCALL                                      0  $29     
         35*       INIT_ARRAY                                       ~30     $29
         36*       FETCH_OBJ_R                                      ~31     !1, 'child'
         37*       ADD_ARRAY_ELEMENT                                ~30     ~31
         38*       ADD_ARRAY_ELEMENT                                ~27     ~30
         39*       ADD_ARRAY_ELEMENT                                ~25     ~27
         40*       INIT_ARRAY                                       ~32     ~25, 'get_xml_nodecl'
   56    41*       ASSIGN                                                   !6, ~32
   63    42*       ECHO                                                     'Running+tests+with+LIBXML+'
         43*       ECHO                                                     '2.9.4'
         44*       ECHO                                                     '%3A%0A'
   64    45*       INIT_FCALL_BY_NAME                                       'run_test_suite'
         46*       SEND_VAR_EX                                              !6
         47*       DO_FCALL                                      0          
  134    48*     > RETURN                                                   1

Function simplexml_get_xml_without_declaration:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 29
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
Branch analysis from position: 20
filename:       /in/PKAMV
function name:  simplexml_get_xml_without_declaration
number of ops:  31
compiled vars:  !0 = $element, !1 = $elementNode, !2 = $documentElement, !3 = $xml
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   37     1        INIT_METHOD_CALL                                         !0, 'xpath'
          2        SEND_VAL_EX                                              '.'
          3        DO_FCALL                                      0  $4      
          4        FETCH_LIST_R                                     $5      $4, 0
          5        ASSIGN                                                   !1, $5
          6        FREE                                                     $4
   38     7        INIT_METHOD_CALL                                         !0, 'xpath'
          8        SEND_VAL_EX                                              '%2F%2A'
          9        DO_FCALL                                      0  $7      
         10        FETCH_LIST_R                                     $8      $7, 0
         11        ASSIGN                                                   !2, $8
         12        FREE                                                     $7
   40    13        INIT_METHOD_CALL                                         !0, 'asXML'
         14        DO_FCALL                                      0  $10     
         15        ASSIGN                                                   !3, $10
   42    16        IS_EQUAL                                         ~12     !1, !0
         17      > JMPZ_EX                                          ~12     ~12, ->20
         18    >   IS_EQUAL                                         ~13     !2, !0
         19        BOOL                                             ~12     ~13
         20    > > JMPZ                                                     ~12, ->29
   43    21    >   INIT_FCALL                                               'explode'
         22        SEND_VAL                                                 '%0A'
         23        SEND_VAR                                                 !3
         24        SEND_VAL                                                 2
         25        DO_ICALL                                         $14     
         26        FETCH_LIST_R                                     $15     $14, 1
         27        ASSIGN                                                   !3, $15
         28        FREE                                                     $14
   46    29    > > RETURN                                                   !3
   47    30*     > RETURN                                                   null

End of function simplexml_get_xml_without_declaration

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/PKAMV
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
-------------------------------------------------------------------------------------
   66     0  E >   RECV                                             !0      
   69     1      > FE_RESET_R                                       $8      !0, ->18
          2    > > FE_FETCH_R                                       ~9      $8, !1, ->18
          3    >   ASSIGN                                                   !2, ~9
   70     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
   71    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
   69    17      > JMP                                                      ->2
         18    >   FE_FREE                                                  $8
   73    19        ECHO                                                     '%0A'
   75    20        ASSIGN_DIM                                               !6, 'tests'
         21        OP_DATA                                                  0
   76    22        ASSIGN_DIM                                               !6, 'failures'
         23        OP_DATA                                                  0
   78    24      > FE_RESET_R                                       $20     !5, ->35
         25    > > FE_FETCH_R                                               $20, !7, ->35
   79    26    >   FETCH_DIM_R                                      ~22     !7, 'tests'
         27        ASSIGN_DIM_OP                +=               1          !6, 'tests'
         28        OP_DATA                                                  ~22
   80    29        FETCH_DIM_R                                      ~24     !7, 'failures'
         30        ASSIGN_DIM_OP                +=               1          !6, 'failures'
         31        OP_DATA                                                  ~24
   81    32        FETCH_DIM_R                                      ~25     !7, 'messages'
         33        ECHO                                                     ~25
   78    34      > JMP                                                      ->25
         35    >   FE_FREE                                                  $20
   84    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                                                 
   85    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/PKAMV
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
-------------------------------------------------------------------------------------
   87     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
   89     3        TYPE_CHECK                                    2          !2
          4      > JMPZ                                                     ~13, ->6
          5    >   ASSIGN                                                   !2, !1
   91     6    >   ASSIGN_DIM                                               !3, 'tests'
          7        OP_DATA                                                  0
   92     8        ASSIGN_DIM                                               !3, 'failures'
          9        OP_DATA                                                  0
   94    10        ASSIGN                                                   !4, ''
   96    11      > FE_RESET_R                                       $18     !0, ->59
         12    > > FE_FETCH_R                                       ~19     $18, !5, ->59
         13    >   ASSIGN                                                   !6, ~19
   97    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
   98    25        CONCAT                                           ~30     !2, '+'
         26        CONCAT                                           ~31     ~30, !9
         27        ASSIGN                                                   !10, ~31
   99    28        INIT_FCALL                                               'ob_start'
         29        DO_ICALL                                                 
  100    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
  101    37        INIT_FCALL                                               'ob_get_clean'
         38        DO_ICALL                                         $36     
         39        ASSIGN                                                   !12, $36
  102    40      > JMPZ                                                     !11, ->43
         41    >   QM_ASSIGN                                        ~38     '.'
         42      > JMP                                                      ->44
         43    >   QM_ASSIGN                                        ~38     'F'
         44    >   ECHO                                                     ~38
  103    45      > JMPZ                                                     !12, ->52
  104    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
  105    51        ASSIGN_OP                                     8          !4, !12
  108    52    >   FETCH_DIM_RW                                     $42     !3, 'tests'
         53        PRE_INC                                                  $42
  109    54        BOOL_NOT                                         ~44     !11
         55      > JMPZ                                                     ~44, ->58
         56    >   FETCH_DIM_RW                                     $45     !3, 'failures'
         57        PRE_INC                                                  $45
   96    58    > > JMP                                                      ->12
         59    >   FE_FREE                                                  $18
  112    60        INIT_ARRAY                                       ~47     !4, 'messages'
         61        ADD                                              ~48     !3, ~47
         62      > RETURN                                                   ~48
  113    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/PKAMV
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
-------------------------------------------------------------------------------------
  115     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
  117     4        INIT_USER_CALL                                1          'call_user_func', !2
          5        SEND_USER                                                !1
          6        DO_FCALL                                      0  $7      
          7        ASSIGN                                                   !4, $7
  118     8        INSTANCEOF                                       ~9      !0, 'SimpleXMLElement'
          9      > JMPZ_EX                                          ~9      ~9, ->12
         10    >   INSTANCEOF                                       ~10     !4, 'SimpleXMLElement'
         11        BOOL                                             ~9      ~10
         12    > > JMPZ                                                     ~9, ->16
  119    13    >   IS_EQUAL                                         ~11     !4, !0
         14        ASSIGN                                                   !5, ~11
         15      > JMP                                                      ->18
  121    16    >   IS_IDENTICAL                                     ~13     !4, !0
         17        ASSIGN                                                   !5, ~13
  124    18    >   BOOL_NOT                                         ~15     !5
         19      > JMPZ                                                     ~15, ->48
  125    20    >   ASSIGN                                                   !6, ''
  126    21        INSTANCEOF                                               !1, 'SimpleXMLElement'
         22      > JMPZ                                                     ~17, ->33
  127    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
  129    33    >   INIT_FCALL                                               'printf'
         34        SEND_VAL                                                 'FAILED+to+test+%25s%25s.%0A'
         35        SEND_VAR                                                 !3
         36        SEND_VAR                                                 !6
         37        DO_ICALL                                                 
  130    38        ECHO                                                     'expected%3A+'
         39        INIT_FCALL                                               'var_dump'
         40        SEND_VAR                                                 !0
         41        DO_ICALL                                         $23     
         42        ECHO                                                     $23
  131    43        ECHO                                                     'actual%3A'
         44        INIT_FCALL                                               'var_dump'
         45        SEND_VAR                                                 !4
         46        DO_ICALL                                         $24     
         47        ECHO                                                     $24
  133    48    > > RETURN                                                   !5
  134    49*     > RETURN                                                   null

End of function run_test

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.39 ms | 1420 KiB | 31 Q