3v4l.org

run code in 300+ PHP versions simultaneously
<?php function test_iterator($dirname) { $files = array(); $dir = new DirectoryIterator($dirname); while($dir->valid()) { $files[] = (string)$dir->current(); $dir->next(); } return $files; } function test_iterator_bug($dirname) { $files = array(); $dir = new DirectoryIterator($dirname); foreach($dir as $file) { $files[] = (string)$file; } return $files; } echo 'PHP version: ' . phpversion() . "\n\n"; $dirname = dirname(__FILE__); foreach (array('iterator', 'iterator_bug') as $test_name) { echo "--- {$test_name} ---\n"; $foo = "test_{$test_name}"; var_dump($foo($dirname)); echo "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 26
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 26
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/Q08CR
function name:  (null)
number of ops:  28
compiled vars:  !0 = $dirname, !1 = $test_name, !2 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   INIT_FCALL                                               'phpversion'
          1        DO_ICALL                                         $3      
          2        CONCAT                                           ~4      'PHP+version%3A+', $3
          3        CONCAT                                           ~5      ~4, '%0A%0A'
          4        ECHO                                                     ~5
   24     5        INIT_FCALL                                               'dirname'
          6        SEND_VAL                                                 '%2Fin%2FQ08CR'
          7        DO_ICALL                                         $6      
          8        ASSIGN                                                   !0, $6
   25     9      > FE_RESET_R                                       $8      <array>, ->26
         10    > > FE_FETCH_R                                               $8, !1, ->26
   26    11    >   ROPE_INIT                                     3  ~10     '---+'
         12        ROPE_ADD                                      1  ~10     ~10, !1
         13        ROPE_END                                      2  ~9      ~10, '+---%0A'
         14        ECHO                                                     ~9
   27    15        NOP                                                      
         16        FAST_CONCAT                                      ~12     'test_', !1
         17        ASSIGN                                                   !2, ~12
   28    18        INIT_FCALL                                               'var_dump'
         19        INIT_DYNAMIC_CALL                                        !2
         20        SEND_VAR_EX                                              !0
         21        DO_FCALL                                      0  $14     
         22        SEND_VAR                                                 $14
         23        DO_ICALL                                                 
   29    24        ECHO                                                     '%0A'
   25    25      > JMP                                                      ->10
         26    >   FE_FREE                                                  $8
   30    27      > RETURN                                                   1

Function test_iterator:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 7
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 7
Branch analysis from position: 17
Branch analysis from position: 7
filename:       /in/Q08CR
function name:  test_iterator
number of ops:  19
compiled vars:  !0 = $dirname, !1 = $files, !2 = $dir
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        ASSIGN                                                   !1, <array>
    5     2        NEW                                              $4      'DirectoryIterator'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !2, $4
    6     6      > JMP                                                      ->14
    7     7    >   INIT_METHOD_CALL                                         !2, 'current'
          8        DO_FCALL                                      0  $8      
          9        CAST                                          6  ~9      $8
         10        ASSIGN_DIM                                               !1
         11        OP_DATA                                                  ~9
    8    12        INIT_METHOD_CALL                                         !2, 'next'
         13        DO_FCALL                                      0          
    6    14    >   INIT_METHOD_CALL                                         !2, 'valid'
         15        DO_FCALL                                      0  $11     
         16      > JMPNZ                                                    $11, ->7
   10    17    > > RETURN                                                   !1
   11    18*     > RETURN                                                   null

End of function test_iterator

Function test_iterator_bug:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/Q08CR
function name:  test_iterator_bug
number of ops:  15
compiled vars:  !0 = $dirname, !1 = $files, !2 = $dir, !3 = $file
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   14     1        ASSIGN                                                   !1, <array>
   16     2        NEW                                              $5      'DirectoryIterator'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !2, $5
   17     6      > FE_RESET_R                                       $8      !2, ->12
          7    > > FE_FETCH_R                                               $8, !3, ->12
   18     8    >   CAST                                          6  ~10     !3
          9        ASSIGN_DIM                                               !1
         10        OP_DATA                                                  ~10
   17    11      > JMP                                                      ->7
         12    >   FE_FREE                                                  $8
   20    13      > RETURN                                                   !1
   21    14*     > RETURN                                                   null

End of function test_iterator_bug

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.4 ms | 1400 KiB | 19 Q