3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Acme\FizzBuzz; use Generator; /** * Create a sequence of numbers and words that match the current offset. * * @param array<int,string> $dictionary * @param int $start * @param int $size * @param int $step * @param int $modulo * * @yield string * @return Generator */ function createSequence( array $dictionary, int $start, int $size, int $step = 1, int $modulo = 0 ): Generator { for ($index = $start; $index <= $size; $index += $step) { $entry = ''; foreach ($dictionary as $offset => $word) { if ($index % $offset === $modulo) { $entry .= $word; } } yield $entry === '' ? $index : $entry; } } // Write a short program that prints each number from 1 to 100. // For each multiple of 3, print "Fizz" instead of the number. // For each multiple of 5, print "Buzz" instead of the number. // For numbers which are multiples of both 3 and 5, print "FizzBuzz" instead of the number. $sequence = \Acme\FizzBuzz\createSequence( [ 3 => 'Fizz', 5 => 'Buzz' ], 1, 100 ); foreach ($sequence as $entry) { echo $entry . PHP_EOL; }
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/D5KfK
function name:  (null)
number of ops:  14
compiled vars:  !0 = $sequence, !1 = $entry
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   INIT_FCALL                                               'acme%5Cfizzbuzz%5Ccreatesequence'
   45     1        SEND_VAL                                                 <array>
   48     2        SEND_VAL                                                 1
   49     3        SEND_VAL                                                 100
          4        DO_FCALL                                      0  $2      
   43     5        ASSIGN                                                   !0, $2
   52     6      > FE_RESET_R                                       $4      !0, ->12
          7    > > FE_FETCH_R                                               $4, !1, ->12
   53     8    >   FETCH_CONSTANT                                   ~5      'Acme%5CFizzBuzz%5CPHP_EOL'
          9        CONCAT                                           ~6      !1, ~5
         10        ECHO                                                     ~6
   52    11      > JMP                                                      ->7
         12    >   FE_FREE                                                  $4
   54    13      > RETURN                                                   1

Function acme%5Cfizzbuzz%5Ccreatesequence:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 8
Branch analysis from position: 27
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 17
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 17
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 16
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 8
Branch analysis from position: 27
Branch analysis from position: 8
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 8
Branch analysis from position: 27
Branch analysis from position: 8
Branch analysis from position: 17
filename:       /in/D5KfK
function name:  Acme\FizzBuzz\createSequence
number of ops:  28
compiled vars:  !0 = $dictionary, !1 = $start, !2 = $size, !3 = $step, !4 = $modulo, !5 = $index, !6 = $entry, !7 = $word, !8 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      1
          4        RECV_INIT                                        !4      0
          5        GENERATOR_CREATE                                         
   26     6        ASSIGN                                                   !5, !1
          7      > JMP                                                      ->25
   27     8    >   ASSIGN                                                   !6, ''
   28     9      > FE_RESET_R                                       $11     !0, ->17
         10    > > FE_FETCH_R                                       ~12     $11, !7, ->17
         11    >   ASSIGN                                                   !8, ~12
   29    12        MOD                                              ~14     !5, !8
         13        IS_IDENTICAL                                             !4, ~14
         14      > JMPZ                                                     ~15, ->16
   30    15    >   ASSIGN_OP                                     8          !6, !7
   28    16    > > JMP                                                      ->10
         17    >   FE_FREE                                                  $11
   34    18        IS_IDENTICAL                                             !6, ''
         19      > JMPZ                                                     ~17, ->22
         20    >   QM_ASSIGN                                        ~18     !5
         21      > JMP                                                      ->23
         22    >   QM_ASSIGN                                        ~18     !6
         23    >   YIELD                                                    ~18
   26    24        ASSIGN_OP                                     1          !5, !3
         25    >   IS_SMALLER_OR_EQUAL                                      !5, !2
         26      > JMPNZ                                                    ~21, ->8
   36    27    > > GENERATOR_RETURN                                         

End of function acme%5Cfizzbuzz%5Ccreatesequence

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.04 ms | 1403 KiB | 14 Q