3v4l.org

run code in 500+ PHP versions simultaneously
<?php function iterateOverIt($iterable) { // First foreach acts like a guard condition foreach ($iterable as $_) { // Pre-processing: echo "<ul>\n"; // Real looping, this won't start a *NEW* iteration process but will continue the one started above: foreach ($iterable as $item) { echo "<li>", $item instanceof DateTime ? $item->format("c") : ( isset($item["col"]) ? $item["col"] : $item ), "</li>\n"; } // Post-processing: echo "</ul>\n"; break; } } // Empty array iterateOverIt([]); iterateOverIt([1, 2, 3]); // Empty generator iterateOverIt(function () : Generator { return; yield; }); iterateOverIt((function () : Generator { yield 4; yield 5; yield 6; })()); // Class with no public properties iterateOverIt(new stdClass()); iterateOverIt(new class { public $a = 7, $b = 8, $c = 9;}); /* $db = mysqli_connect("localhost", "user", "pass", "db"); // Empty resultset iterateOverIt($db->query("SELECT 0 FROM DUAL WHERE false")); iterateOverIt($db->query("SELECT 10 AS col UNION SELECT 11 UNION SELECT 12")); */ // DatePeriod generating no dates iterateOverIt(new DatePeriod(new DateTime("2020-01-01 00:00:00"), new DateInterval("P1D"), new DateTime("2020-01-01 00:00:00"), DatePeriod::EXCLUDE_START_DATE)); iterateOverIt(new DatePeriod(new DateTime("2020-01-01 00:00:00"), new DateInterval("P1D"), 3, DatePeriod::EXCLUDE_START_DATE));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2M47K
function name:  (null)
number of ops:  61
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   24     0  E >   INIT_FCALL                                                   'iterateoverit'
          1        SEND_VAL                                                     <array>
          2        DO_FCALL                                          0          
   25     3        INIT_FCALL                                                   'iterateoverit'
          4        SEND_VAL                                                     <array>
          5        DO_FCALL                                          0          
   28     6        INIT_FCALL                                                   'iterateoverit'
          7        DECLARE_LAMBDA_FUNCTION                              ~2      [0]
   31     8        SEND_VAL                                                     ~2
   28     9        DO_FCALL                                          0          
   32    10        INIT_FCALL                                                   'iterateoverit'
         11        DECLARE_LAMBDA_FUNCTION                              ~4      [1]
   36    12        INIT_DYNAMIC_CALL                                            ~4
         13        DO_FCALL                                          0  $5      
         14        SEND_VAR                                                     $5
   32    15        DO_FCALL                                          0          
   39    16        INIT_FCALL                                                   'iterateoverit'
         17        NEW                                                  $7      'stdClass'
         18        DO_FCALL                                          0          
         19        SEND_VAR                                                     $7
         20        DO_FCALL                                          0          
   40    21        INIT_FCALL                                                   'iterateoverit'
         22        DECLARE_ANON_CLASS                                   <unknown> 
         23        NEW                                                  $11     $10
         24        DO_FCALL                                          0          
         25        SEND_VAR                                                     $11
         26        DO_FCALL                                          0          
   50    27        INIT_FCALL                                                   'iterateoverit'
         28        NEW                                                  $14     'DatePeriod'
         29        NEW                                                  $15     'DateTime'
         30        SEND_VAL_EX                                                  '2020-01-01+00%3A00%3A00'
         31        DO_FCALL                                          0          
         32        SEND_VAR_NO_REF_EX                                           $15
         33        NEW                                                  $17     'DateInterval'
         34        SEND_VAL_EX                                                  'P1D'
         35        DO_FCALL                                          0          
         36        SEND_VAR_NO_REF_EX                                           $17
         37        NEW                                                  $19     'DateTime'
         38        SEND_VAL_EX                                                  '2020-01-01+00%3A00%3A00'
         39        DO_FCALL                                          0          
         40        SEND_VAR_NO_REF_EX                                           $19
         41        SEND_VAL_EX                                                  1
         42        DO_FCALL                                          0          
         43        SEND_VAR                                                     $14
         44        DO_FCALL                                          0          
   51    45        INIT_FCALL                                                   'iterateoverit'
         46        NEW                                                  $23     'DatePeriod'
         47        NEW                                                  $24     'DateTime'
         48        SEND_VAL_EX                                                  '2020-01-01+00%3A00%3A00'
         49        DO_FCALL                                          0          
         50        SEND_VAR_NO_REF_EX                                           $24
         51        NEW                                                  $26     'DateInterval'
         52        SEND_VAL_EX                                                  'P1D'
         53        DO_FCALL                                          0          
         54        SEND_VAR_NO_REF_EX                                           $26
         55        SEND_VAL_EX                                                  3
         56        SEND_VAL_EX                                                  1
         57        DO_FCALL                                          0          
         58        SEND_VAR                                                     $23
         59        DO_FCALL                                          0          
         60      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/2M47K
function name:  {closure:/in/2M47K:28}
number of ops:  4
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   28     0  E >   GENERATOR_CREATE                                             
   29     1      > GENERATOR_RETURN                                             
   30     2*       YIELD                                                        
   31     3*     > GENERATOR_RETURN                                             

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/2M47K
function name:  {closure:/in/2M47K:32}
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   32     0  E >   GENERATOR_CREATE                                             
   33     1        YIELD                                                        4
   34     2        YIELD                                                        5
   35     3        YIELD                                                        6
   36     4      > GENERATOR_RETURN                                             

End of Dynamic Function 1

Function iterateoverit:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 28
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 28
Branch analysis from position: 3
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 24
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 24
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 19
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
Branch analysis from position: 28
Branch analysis from position: 28
filename:       /in/2M47K
function name:  iterateOverIt
number of ops:  30
compiled vars:  !0 = $iterable, !1 = $_, !2 = $item
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
    5     1      > FE_RESET_R                                           $3      !0, ->28
          2    > > FE_FETCH_R                                                   $3, !1, ->28
    8     3    >   ECHO                                                         '%3Cul%3E%0A'
   11     4      > FE_RESET_R                                           $4      !0, ->24
          5    > > FE_FETCH_R                                                   $4, !2, ->24
   12     6    >   ECHO                                                         '%3Cli%3E'
          7        INSTANCEOF                                                   !2, 'DateTime'
          8      > JMPZ                                                         ~5, ->14
          9    >   INIT_METHOD_CALL                                             !2, 'format'
         10        SEND_VAL_EX                                                  'c'
         11        DO_FCALL                                          0  $6      
         12        QM_ASSIGN                                            ~7      $6
         13      > JMP                                                          ->21
   13    14    >   ISSET_ISEMPTY_DIM_OBJ                             0          !2, 'col'
         15      > JMPZ                                                         ~8, ->19
         16    >   FETCH_DIM_R                                          ~9      !2, 'col'
         17        QM_ASSIGN                                            ~10     ~9
         18      > JMP                                                          ->20
         19    >   QM_ASSIGN                                            ~10     !2
         20    >   QM_ASSIGN                                            ~7      ~10
         21    >   ECHO                                                         ~7
   14    22        ECHO                                                         '%3C%2Fli%3E%0A'
   11    23      > JMP                                                          ->5
         24    >   FE_FREE                                                      $4
   18    25        ECHO                                                         '%3C%2Ful%3E%0A'
   19    26      > JMP                                                          ->28
    5    27*       JMP                                                          ->2
         28    >   FE_FREE                                                      $3
   21    29      > RETURN                                                       null

End of function iterateoverit

Class class@anonymous: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
224.8 ms | 2172 KiB | 21 Q