3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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
Jump found. (Code = 77) Position 1 = 8, Position 2 = 13
Branch analysis from position: 8
Jump found. (Code = 78) Position 1 = 9, Position 2 = 13
Branch analysis from position: 9
Jump found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 13
Jump found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/D5KfK
function name:  (null)
number of ops:  15
compiled vars:  !0 = $sequence, !1 = $entry
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  19     0  E >   NOP                                                      
  43     1        INIT_FCALL                                               'acme%5Cfizzbuzz%5Ccreatesequence'
  45     2        SEND_VAL                                                 <array>
  48     3        SEND_VAL                                                 1
  49     4        SEND_VAL                                                 100
         5        DO_FCALL                                      0  $2      
         6        ASSIGN                                                   !0, $2
  52     7      > FE_RESET_R                                       $4      !0, ->13
         8    > > FE_FETCH_R                                               $4, !1, ->13
  53     9    >   FETCH_CONSTANT                                   ~5      'Acme%5CFizzBuzz%5CPHP_EOL'
        10        CONCAT                                           ~6      !1, ~5
        11        ECHO                                                     ~6
        12      > JMP                                                      ->8
        13    >   FE_FREE                                                  $4
  54    14      > RETURN                                                   1

Function acme%5Cfizzbuzz%5Ccreatesequence:
Finding entry points
Branch analysis from position: 0
Jump found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Jump found. (Code = 44) Position 1 = 27, Position 2 = 8
Branch analysis from position: 27
Jump found. (Code = 161) Position 1 = -2
Branch analysis from position: 8
Jump found. (Code = 77) Position 1 = 10, Position 2 = 17
Branch analysis from position: 10
Jump found. (Code = 78) Position 1 = 11, Position 2 = 17
Branch analysis from position: 11
Jump found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
Jump found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 16
Branch analysis from position: 17
Jump found. (Code = 43) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
Jump found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Jump found. (Code = 44) Position 1 = 27, Position 2 = 8
Branch analysis from position: 27
Branch analysis from position: 8
Branch analysis from position: 22
Jump 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                                     ~15     ~14, !4
        14      > JMPZ                                                     ~15, ->16
  30    15    >   ASSIGN_CONCAT                                 0          !6, !7
        16    > > JMP                                                      ->10
        17    >   FE_FREE                                                  $11
  34    18        IS_IDENTICAL                                     ~17     !6, ''
        19      > JMPZ                                                     ~17, ->22
        20    >   QM_ASSIGN                                        ~18     !5
        21      > JMP                                                      ->23
        22    >   QM_ASSIGN                                        ~18     !6
        23    >   YIELD                                                    ~18
  26    24        ASSIGN_ADD                                    0          !5, !3
        25    >   IS_SMALLER_OR_EQUAL                              ~21     !5, !2
        26      > JMPNZ                                                    ~21, ->8
  36    27    > > GENERATOR_RETURN                                         

End of function acme%5Cfizzbuzz%5Ccreatesequence

Generated using Vulcan Logic Dumper, using php 7.2.0