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 bool */ function simplexml_is_attributes(SimpleXMLElement $element) { return $element->attributes() === NULL; } $documentElement = $simple; $attributeList = $simple->child->grandchild->attributes(); $attributeListEmpty = $simple->child->attributes(); $attribute = $simple->child->grandchild['a1']; $suite = array( 'is_attributes' => array('simplexml_is_attributes', array( array(false, $attribute), array(true, $attributeList), array(true, $attributeListEmpty), array(false, $documentElement), array(false, $documentElement->child), array(false, $documentElement->child[0]), )), ); 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/ZTVDE
function name:  (null)
number of ops:  54
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
   37     8        ASSIGN                                                   !2, !1
   38     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
   39    14        FETCH_OBJ_R                                      ~17     !1, 'child'
         15        INIT_METHOD_CALL                                         ~17, 'attributes'
         16        DO_FCALL                                      0  $18     
         17        ASSIGN                                                   !4, $18
   40    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
   44    22        INIT_ARRAY                                       ~24     'simplexml_is_attributes'
         23        INIT_ARRAY                                       ~25     <false>
   45    24        ADD_ARRAY_ELEMENT                                ~25     !5
         25        INIT_ARRAY                                       ~26     ~25
   44    26        INIT_ARRAY                                       ~27     <true>
   46    27        ADD_ARRAY_ELEMENT                                ~27     !3
         28        ADD_ARRAY_ELEMENT                                ~26     ~27
   44    29        INIT_ARRAY                                       ~28     <true>
   47    30        ADD_ARRAY_ELEMENT                                ~28     !4
         31        ADD_ARRAY_ELEMENT                                ~26     ~28
   44    32        INIT_ARRAY                                       ~29     <false>
   48    33        ADD_ARRAY_ELEMENT                                ~29     !2
         34        ADD_ARRAY_ELEMENT                                ~26     ~29
   44    35        INIT_ARRAY                                       ~30     <false>
   49    36        FETCH_OBJ_R                                      ~31     !2, 'child'
         37        ADD_ARRAY_ELEMENT                                ~30     ~31
         38        ADD_ARRAY_ELEMENT                                ~26     ~30
   44    39        INIT_ARRAY                                       ~32     <false>
   50    40        FETCH_OBJ_R                                      ~33     !2, 'child'
         41        FETCH_DIM_R                                      ~34     ~33, 0
         42        ADD_ARRAY_ELEMENT                                ~32     ~34
         43        ADD_ARRAY_ELEMENT                                ~26     ~32
         44        ADD_ARRAY_ELEMENT                                ~24     ~26
         45        INIT_ARRAY                                       ~35     ~24, 'is_attributes'
   43    46        ASSIGN                                                   !6, ~35
   54    47        ECHO                                                     'Running+tests+with+LIBXML+'
         48        ECHO                                                     '2.9.4'
         49        ECHO                                                     '%3A%0A'
   55    50        INIT_FCALL_BY_NAME                                       'run_test_suite'
         51        SEND_VAR_EX                                              !6
         52        DO_FCALL                                      0          
  125    53      > RETURN                                                   1

Function simplexml_is_attributes:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZTVDE
function name:  simplexml_is_attributes
number of ops:  6
compiled vars:  !0 = $element
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   33     1        INIT_METHOD_CALL                                         !0, 'attributes'
          2        DO_FCALL                                      0  $1      
          3        TYPE_CHECK                                    2  ~2      $1
          4      > RETURN                                                   ~2
   34     5*     > RETURN                                                   null

End of function simplexml_is_attributes

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

End of function run_test

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.47 ms | 1408 KiB | 27 Q