3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test { protected $path = '/tmp/directory'; public function createTestFiles () { $amount = 63; if (!is_dir($this->path)) { mkdir($this->path); } foreach (scandir($this->path) as $filename) { @unlink("{$this->path}/$filename"); } for ($num = 1; $num <= $amount; $num++) { fopen("{$this->path}/{$num}.txt", "a"); } } public function runTest() { echo 'get by foreach: ' . $this->getByForeach() . PHP_EOL; echo 'get by foreach with rewind: ' . $this->getByForeachWithRewind() . PHP_EOL; echo 'get by foreach after foreach: ' . $this->getByForeachAfterForeach() . PHP_EOL; echo 'get by loop: ' . $this->getByloop() . PHP_EOL; echo 'get by iterator_to_array: ' . $this->getByIteratorToArray() . PHP_EOL; echo 'get by iterator_to_array with rewind: ' . $this->getByIteratorToArrayWithRewind() . PHP_EOL; } public function getByForeach() { $directory = new RecursiveDirectoryIterator($this->path); $count = 0; foreach ($directory as $filename => $fileInfo) { $count++; } return $count; } public function getByForeachWithRewind() { $directory = new RecursiveDirectoryIterator($this->path); $count = 0; $directory->rewind(); foreach ($directory as $filename => $fileInfo) { $count++; } return $count; } public function getByForeachAfterForeach() { $directory = new RecursiveDirectoryIterator($this->path); $count = 0; foreach ($directory as $filename => $fileInfo) { // do nothing } foreach ($directory as $filename => $fileInfo) { $count++; } return $count; } public function getByLoop() { $directory = new RecursiveDirectoryIterator($this->path); $count = 0; while ($directory->valid()) { $count++; $directory->next(); } return $count; } public function getByIteratorToArray() { $directory = new RecursiveDirectoryIterator($this->path); return count(iterator_to_array($directory)); } public function getByIteratorToArrayWithRewind() { $directory = new RecursiveDirectoryIterator($this->path); $directory->rewind(); return count(iterator_to_array($directory)); } } $test = new Test(); $test->createTestFiles(); $test->runTest(); # comment so that 3v4l sees a change in the file
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CC6QC
function name:  (null)
number of ops:  8
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   97     0  E >   NEW                                              $1      'Test'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   98     3        INIT_METHOD_CALL                                         !0, 'createTestFiles'
          4        DO_FCALL                                      0          
   99     5        INIT_METHOD_CALL                                         !0, 'runTest'
          6        DO_FCALL                                      0          
  101     7      > RETURN                                                   1

Class Test:
Function createtestfiles:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 27
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 27
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 30
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 30
Branch analysis from position: 42
Branch analysis from position: 30
Branch analysis from position: 27
Branch analysis from position: 11
filename:       /in/CC6QC
function name:  createTestFiles
number of ops:  43
compiled vars:  !0 = $amount, !1 = $filename, !2 = $num
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   ASSIGN                                                   !0, 63
   11     1        INIT_FCALL                                               'is_dir'
          2        FETCH_OBJ_R                                      ~4      'path'
          3        SEND_VAL                                                 ~4
          4        DO_ICALL                                         $5      
          5        BOOL_NOT                                         ~6      $5
          6      > JMPZ                                                     ~6, ->11
   12     7    >   INIT_FCALL                                               'mkdir'
          8        FETCH_OBJ_R                                      ~7      'path'
          9        SEND_VAL                                                 ~7
         10        DO_ICALL                                                 
   15    11    >   INIT_FCALL                                               'scandir'
         12        FETCH_OBJ_R                                      ~9      'path'
         13        SEND_VAL                                                 ~9
         14        DO_ICALL                                         $10     
         15      > FE_RESET_R                                       $11     $10, ->27
         16    > > FE_FETCH_R                                               $11, !1, ->27
   16    17    >   BEGIN_SILENCE                                    ~12     
         18        INIT_FCALL                                               'unlink'
         19        FETCH_OBJ_R                                      ~13     'path'
         20        ROPE_INIT                                     3  ~15     ~13
         21        ROPE_ADD                                      1  ~15     ~15, '%2F'
         22        ROPE_END                                      2  ~14     ~15, !1
         23        SEND_VAL                                                 ~14
         24        DO_ICALL                                                 
         25        END_SILENCE                                              ~12
   15    26      > JMP                                                      ->16
         27    >   FE_FREE                                                  $11
   19    28        ASSIGN                                                   !2, 1
         29      > JMP                                                      ->40
   20    30    >   INIT_FCALL                                               'fopen'
         31        FETCH_OBJ_R                                      ~19     'path'
         32        ROPE_INIT                                     4  ~21     ~19
         33        ROPE_ADD                                      1  ~21     ~21, '%2F'
         34        ROPE_ADD                                      2  ~21     ~21, !2
         35        ROPE_END                                      3  ~20     ~21, '.txt'
         36        SEND_VAL                                                 ~20
         37        SEND_VAL                                                 'a'
         38        DO_ICALL                                                 
   19    39        PRE_INC                                                  !2
         40    >   IS_SMALLER_OR_EQUAL                                      !2, !0
         41      > JMPNZ                                                    ~25, ->30
   22    42    > > RETURN                                                   null

End of function createtestfiles

Function runtest:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CC6QC
function name:  runTest
number of ops:  31
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   INIT_METHOD_CALL                                         'getByForeach'
          1        DO_FCALL                                      0  $0      
          2        CONCAT                                           ~1      'get+by+foreach%3A+', $0
          3        CONCAT                                           ~2      ~1, '%0A'
          4        ECHO                                                     ~2
   27     5        INIT_METHOD_CALL                                         'getByForeachWithRewind'
          6        DO_FCALL                                      0  $3      
          7        CONCAT                                           ~4      'get+by+foreach+with+rewind%3A+', $3
          8        CONCAT                                           ~5      ~4, '%0A'
          9        ECHO                                                     ~5
   28    10        INIT_METHOD_CALL                                         'getByForeachAfterForeach'
         11        DO_FCALL                                      0  $6      
         12        CONCAT                                           ~7      'get+by+foreach+after+foreach%3A+', $6
         13        CONCAT                                           ~8      ~7, '%0A'
         14        ECHO                                                     ~8
   29    15        INIT_METHOD_CALL                                         'getByloop'
         16        DO_FCALL                                      0  $9      
         17        CONCAT                                           ~10     'get+by+loop%3A+', $9
         18        CONCAT                                           ~11     ~10, '%0A'
         19        ECHO                                                     ~11
   30    20        INIT_METHOD_CALL                                         'getByIteratorToArray'
         21        DO_FCALL                                      0  $12     
         22        CONCAT                                           ~13     'get+by+iterator_to_array%3A+', $12
         23        CONCAT                                           ~14     ~13, '%0A'
         24        ECHO                                                     ~14
   31    25        INIT_METHOD_CALL                                         'getByIteratorToArrayWithRewind'
         26        DO_FCALL                                      0  $15     
         27        CONCAT                                           ~16     'get+by+iterator_to_array+with+rewind%3A+', $15
         28        CONCAT                                           ~17     ~16, '%0A'
         29        ECHO                                                     ~17
   32    30      > RETURN                                                   null

End of function runtest

Function getbyforeach:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 12
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/CC6QC
function name:  getByForeach
number of ops:  15
compiled vars:  !0 = $directory, !1 = $count, !2 = $fileInfo, !3 = $filename
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   NEW                                              $4      'RecursiveDirectoryIterator'
          1        CHECK_FUNC_ARG                                           
          2        FETCH_OBJ_FUNC_ARG                               $5      'path'
          3        SEND_FUNC_ARG                                            $5
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $4
   37     6        ASSIGN                                                   !1, 0
   38     7      > FE_RESET_R                                       $9      !0, ->12
          8    > > FE_FETCH_R                                       ~10     $9, !2, ->12
          9    >   ASSIGN                                                   !3, ~10
   39    10        PRE_INC                                                  !1
   38    11      > JMP                                                      ->8
         12    >   FE_FREE                                                  $9
   42    13      > RETURN                                                   !1
   43    14*     > RETURN                                                   null

End of function getbyforeach

Function getbyforeachwithrewind:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/CC6QC
function name:  getByForeachWithRewind
number of ops:  17
compiled vars:  !0 = $directory, !1 = $count, !2 = $fileInfo, !3 = $filename
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   NEW                                              $4      'RecursiveDirectoryIterator'
          1        CHECK_FUNC_ARG                                           
          2        FETCH_OBJ_FUNC_ARG                               $5      'path'
          3        SEND_FUNC_ARG                                            $5
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $4
   48     6        ASSIGN                                                   !1, 0
   49     7        INIT_METHOD_CALL                                         !0, 'rewind'
          8        DO_FCALL                                      0          
   50     9      > FE_RESET_R                                       $10     !0, ->14
         10    > > FE_FETCH_R                                       ~11     $10, !2, ->14
         11    >   ASSIGN                                                   !3, ~11
   51    12        PRE_INC                                                  !1
   50    13      > JMP                                                      ->10
         14    >   FE_FREE                                                  $10
   54    15      > RETURN                                                   !1
   55    16*     > RETURN                                                   null

End of function getbyforeachwithrewind

Function getbyforeachafterforeach:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 17
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
Branch analysis from position: 11
filename:       /in/CC6QC
function name:  getByForeachAfterForeach
number of ops:  20
compiled vars:  !0 = $directory, !1 = $count, !2 = $fileInfo, !3 = $filename
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   NEW                                              $4      'RecursiveDirectoryIterator'
          1        CHECK_FUNC_ARG                                           
          2        FETCH_OBJ_FUNC_ARG                               $5      'path'
          3        SEND_FUNC_ARG                                            $5
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $4
   60     6        ASSIGN                                                   !1, 0
   61     7      > FE_RESET_R                                       $9      !0, ->11
          8    > > FE_FETCH_R                                       ~10     $9, !2, ->11
          9    >   ASSIGN                                                   !3, ~10
         10      > JMP                                                      ->8
         11    >   FE_FREE                                                  $9
   64    12      > FE_RESET_R                                       $12     !0, ->17
         13    > > FE_FETCH_R                                       ~13     $12, !2, ->17
         14    >   ASSIGN                                                   !3, ~13
   65    15        PRE_INC                                                  !1
   64    16      > JMP                                                      ->13
         17    >   FE_FREE                                                  $12
   68    18      > RETURN                                                   !1
   69    19*     > RETURN                                                   null

End of function getbyforeachafterforeach

Function getbyloop:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 8
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 8
Branch analysis from position: 14
Branch analysis from position: 8
filename:       /in/CC6QC
function name:  getByLoop
number of ops:  16
compiled vars:  !0 = $directory, !1 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   73     0  E >   NEW                                              $2      'RecursiveDirectoryIterator'
          1        CHECK_FUNC_ARG                                           
          2        FETCH_OBJ_FUNC_ARG                               $3      'path'
          3        SEND_FUNC_ARG                                            $3
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $2
   74     6        ASSIGN                                                   !1, 0
   75     7      > JMP                                                      ->11
   76     8    >   PRE_INC                                                  !1
   77     9        INIT_METHOD_CALL                                         !0, 'next'
         10        DO_FCALL                                      0          
   75    11    >   INIT_METHOD_CALL                                         !0, 'valid'
         12        DO_FCALL                                      0  $9      
         13      > JMPNZ                                                    $9, ->8
   80    14    > > RETURN                                                   !1
   81    15*     > RETURN                                                   null

End of function getbyloop

Function getbyiteratortoarray:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CC6QC
function name:  getByIteratorToArray
number of ops:  12
compiled vars:  !0 = $directory
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   85     0  E >   NEW                                              $1      'RecursiveDirectoryIterator'
          1        CHECK_FUNC_ARG                                           
          2        FETCH_OBJ_FUNC_ARG                               $2      'path'
          3        SEND_FUNC_ARG                                            $2
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $1
   86     6        INIT_FCALL                                               'iterator_to_array'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $5      
          9        COUNT                                            ~6      $5
         10      > RETURN                                                   ~6
   87    11*     > RETURN                                                   null

End of function getbyiteratortoarray

Function getbyiteratortoarraywithrewind:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CC6QC
function name:  getByIteratorToArrayWithRewind
number of ops:  14
compiled vars:  !0 = $directory
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   91     0  E >   NEW                                              $1      'RecursiveDirectoryIterator'
          1        CHECK_FUNC_ARG                                           
          2        FETCH_OBJ_FUNC_ARG                               $2      'path'
          3        SEND_FUNC_ARG                                            $2
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $1
   92     6        INIT_METHOD_CALL                                         !0, 'rewind'
          7        DO_FCALL                                      0          
   93     8        INIT_FCALL                                               'iterator_to_array'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $6      
         11        COUNT                                            ~7      $6
         12      > RETURN                                                   ~7
   94    13*     > RETURN                                                   null

End of function getbyiteratortoarraywithrewind

End of class Test.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.55 ms | 1026 KiB | 19 Q