3v4l.org

run code in 300+ PHP versions simultaneously
<?php function m() { $memory = round(memory_get_usage() / 1024 / 1024, 2); $frame = debug_backtrace(0, 1)[0]; $file = basename($frame['file']); $line = $frame['line']; printf("%s:%d | %sMb\n", $file, $line, $memory); } function gen(): \iterator { $data = str_repeat('x', 10 * 1024 * 1024); $i = 0; while ($data) { m(); yield $data; m(); unset($data); yield; m(); ++$i; // Simulate the API return nothing if ($i == 3) { $data = false; } else { $data = str_repeat('x', 10 * 1024 * 1024); } m(); } }; m(); foreach ($gen = gen() as $k => $v) { $gen->next(); m(); unset($k, $v); m(); } m();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 17
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 17
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/JHS6W
function name:  (null)
number of ops:  21
compiled vars:  !0 = $gen, !1 = $v, !2 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   INIT_FCALL                                               'm'
          1        DO_FCALL                                      0          
   38     2        INIT_FCALL                                               'gen'
          3        DO_FCALL                                      0  $4      
          4        ASSIGN                                           ~5      !0, $4
          5      > FE_RESET_R                                       $6      ~5, ->17
          6    > > FE_FETCH_R                                       ~7      $6, !1, ->17
          7    >   ASSIGN                                                   !2, ~7
   39     8        INIT_METHOD_CALL                                         !0, 'next'
          9        DO_FCALL                                      0          
   40    10        INIT_FCALL                                               'm'
         11        DO_FCALL                                      0          
   41    12        UNSET_CV                                                 !2
         13        UNSET_CV                                                 !1
   42    14        INIT_FCALL                                               'm'
         15        DO_FCALL                                      0          
   38    16      > JMP                                                      ->6
         17    >   FE_FREE                                                  $6
   45    18        INIT_FCALL                                               'm'
         19        DO_FCALL                                      0          
         20      > RETURN                                                   1

Function m:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JHS6W
function name:  m
number of ops:  29
compiled vars:  !0 = $memory, !1 = $frame, !2 = $file, !3 = $line
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   INIT_FCALL                                               'round'
          1        INIT_FCALL                                               'memory_get_usage'
          2        DO_ICALL                                         $4      
          3        DIV                                              ~5      $4, 1024
          4        DIV                                              ~6      ~5, 1024
          5        SEND_VAL                                                 ~6
          6        SEND_VAL                                                 2
          7        DO_ICALL                                         $7      
          8        ASSIGN                                                   !0, $7
    6     9        INIT_FCALL                                               'debug_backtrace'
         10        SEND_VAL                                                 0
         11        SEND_VAL                                                 1
         12        DO_ICALL                                         $9      
         13        FETCH_DIM_R                                      ~10     $9, 0
         14        ASSIGN                                                   !1, ~10
    7    15        INIT_FCALL                                               'basename'
         16        FETCH_DIM_R                                      ~12     !1, 'file'
         17        SEND_VAL                                                 ~12
         18        DO_ICALL                                         $13     
         19        ASSIGN                                                   !2, $13
    8    20        FETCH_DIM_R                                      ~15     !1, 'line'
         21        ASSIGN                                                   !3, ~15
   10    22        INIT_FCALL                                               'printf'
         23        SEND_VAL                                                 '%25s%3A%25d+%7C+%25sMb%0A'
         24        SEND_VAR                                                 !2
         25        SEND_VAR                                                 !3
         26        SEND_VAR                                                 !0
         27        DO_ICALL                                                 
   11    28      > RETURN                                                   null

End of function m

Function gen:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 8
Branch analysis from position: 30
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 8
Branch analysis from position: 30
Branch analysis from position: 8
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 8
Branch analysis from position: 30
Branch analysis from position: 8
filename:       /in/JHS6W
function name:  gen
number of ops:  31
compiled vars:  !0 = $data, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   GENERATOR_CREATE                                         
   15     1        INIT_FCALL                                               'str_repeat'
          2        SEND_VAL                                                 'x'
          3        SEND_VAL                                                 10485760
          4        DO_ICALL                                         $2      
          5        ASSIGN                                                   !0, $2
   16     6        ASSIGN                                                   !1, 0
   18     7      > JMP                                                      ->29
   19     8    >   INIT_FCALL                                               'm'
          9        DO_FCALL                                      0          
   20    10        YIELD                                                    !0
   21    11        INIT_FCALL                                               'm'
         12        DO_FCALL                                      0          
   22    13        UNSET_CV                                                 !0
   23    14        YIELD                                                    
   24    15        INIT_FCALL                                               'm'
         16        DO_FCALL                                      0          
   25    17        PRE_INC                                                  !1
   27    18        IS_EQUAL                                                 !1, 3
         19      > JMPZ                                                     ~11, ->22
   28    20    >   ASSIGN                                                   !0, <false>
         21      > JMP                                                      ->27
   30    22    >   INIT_FCALL                                               'str_repeat'
         23        SEND_VAL                                                 'x'
         24        SEND_VAL                                                 10485760
         25        DO_ICALL                                         $13     
         26        ASSIGN                                                   !0, $13
   32    27    >   INIT_FCALL                                               'm'
         28        DO_FCALL                                      0          
   18    29    > > JMPNZ                                                    !0, ->8
   34    30    > > GENERATOR_RETURN                                         

End of function gen

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
264.02 ms | 1406 KiB | 35 Q