3v4l.org

run code in 500+ PHP versions simultaneously
<?php declare(strict_types=1); stream_wrapper_register('fizzbuzz', FizzBuzzStreamWrapper::class); require 'fizzbuzz://22'; final class FizzBuzzStreamWrapper { private int $counter = 1; private int $length = 15; /** @var resource */ public $context; public function stream_open(string $path, $mode, $options, &$opened_path): bool { preg_match('#([\d]+$)#', $path, $matches); $this->length = filter_var( $matches[1] ?? '', FILTER_VALIDATE_INT, ['options' => ['default' => 15]] ); return true; } public function stream_read($count): string|false { if ($this->counter > $this->length) { return false; } $fizzbuzz = match (true) { $this->counter % 15 === 0 => 'FizzBuzz', $this->counter % 5 === 0 => 'Buzz', $this->counter % 3 === 0 => 'Fizz', default => (string)$this->counter }; $contents = ''; if ($this->counter === 1) { $contents = '<?php ' . PHP_EOL; } $contents .= "echo '{$fizzbuzz}' . PHP_EOL;"; $this->counter++; return $contents; } public function stream_close(): bool { return true; } public function stream_eof(): bool { return $this->counter ===$this->length; } public function stream_stat(): array|false { return ['size' => 0]; // return ['size' => $this->getSize()]; } public function stream_set_option(int $option, int $arg1, int $arg2) { return false; } private function getSize() { $ret = strlen("<?php \n") + $this->length * 18; $range = range(1, $this->length); $numbers = array_filter($range, fn ($n) => ($n % 3 !== 0 && $n % 5 !== 0)); $ret += strlen(implode('', $numbers)); $fizzOrBuzzs = array_filter($range, fn ($n) => ($n % 15 !== 0) && ($n % 3 === 0 || $n % 5 === 0)); $ret += strlen('fizz') * count($fizzOrBuzzs); $fizzbuzzs = array_filter($range, fn ($n) => ($n % 15 === 0)); $ret += strlen('fizzbuzz') * count($fizzbuzzs); return $ret; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gjHtc
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   INIT_FCALL                                                   'stream_wrapper_register'
          1        SEND_VAL                                                     'fizzbuzz'
          2        SEND_VAL                                                     'FizzBuzzStreamWrapper'
          3        DO_ICALL                                                     
    6     4        INCLUDE_OR_EVAL                                              'fizzbuzz%3A%2F%2F22', REQUIRE
   87     5      > RETURN                                                       1

Class FizzBuzzStreamWrapper:
Function stream_open:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gjHtc
function name:  stream_open
number of ops:  22
compiled vars:  !0 = $path, !1 = $mode, !2 = $options, !3 = $opened_path, !4 = $matches
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   18     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
          3        RECV                                                 !3      
   20     4        INIT_FCALL                                                   'preg_match'
          5        SEND_VAL                                                     '%23%28%5B%5Cd%5D%2B%24%29%23'
          6        SEND_VAR                                                     !0
          7        SEND_REF                                                     !4
          8        DO_ICALL                                                     
   21     9        INIT_FCALL                                                   'filter_var'
   22    10        FETCH_DIM_IS                                         ~7      !4, 1
         11        COALESCE                                             ~8      ~7
         12        QM_ASSIGN                                            ~8      ''
         13        SEND_VAL                                                     ~8
   23    14        SEND_VAL                                                     257
   24    15        SEND_VAL                                                     <array>
   21    16        DO_ICALL                                             $9      
         17        ASSIGN_OBJ                                                   'length'
   24    18        OP_DATA                                                      $9
   27    19      > RETURN                                                       <true>
   28    20*       VERIFY_RETURN_TYPE                                           
         21*     > RETURN                                                       null

End of function stream_open

Function stream_read:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 22
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 24
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 26
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 38
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
filename:       /in/gjHtc
function name:  stream_read
number of ops:  47
compiled vars:  !0 = $count, !1 = $fizzbuzz, !2 = $contents
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   30     0  E >   RECV                                                 !0      
   32     1        FETCH_OBJ_R                                          ~3      'counter'
          2        FETCH_OBJ_R                                          ~4      'length'
          3        IS_SMALLER                                                   ~4, ~3
          4      > JMPZ                                                         ~5, ->6
   33     5    > > RETURN                                                       <false>
   37     6    >   FETCH_OBJ_R                                          ~7      'counter'
          7        MOD                                                  ~8      ~7, 15
          8        IS_IDENTICAL                                         ~9      ~8, 0
          9        IS_IDENTICAL                                                 ~9, <true>
         10      > JMPNZ                                                        ~6, ->22
   38    11    >   FETCH_OBJ_R                                          ~10     'counter'
         12        MOD                                                  ~11     ~10, 5
         13        IS_IDENTICAL                                         ~12     ~11, 0
         14        IS_IDENTICAL                                                 ~12, <true>
         15      > JMPNZ                                                        ~6, ->24
   39    16    >   FETCH_OBJ_R                                          ~13     'counter'
         17        MOD                                                  ~14     ~13, 3
         18        IS_IDENTICAL                                         ~15     ~14, 0
         19        IS_IDENTICAL                                                 ~15, <true>
         20      > JMPNZ                                                        ~6, ->26
         21    > > JMP                                                          ->28
   37    22    >   QM_ASSIGN                                            ~16     'FizzBuzz'
         23      > JMP                                                          ->32
   38    24    >   QM_ASSIGN                                            ~16     'Buzz'
         25      > JMP                                                          ->32
   39    26    >   QM_ASSIGN                                            ~16     'Fizz'
         27      > JMP                                                          ->32
   40    28    >   FETCH_OBJ_R                                          ~17     'counter'
         29        CAST                                              6  ~18     ~17
         30        QM_ASSIGN                                            ~16     ~18
         31      > JMP                                                          ->32
   36    32    >   ASSIGN                                                       !1, ~16
   42    33        ASSIGN                                                       !2, ''
   43    34        FETCH_OBJ_R                                          ~21     'counter'
         35        IS_IDENTICAL                                                 ~21, 1
         36      > JMPZ                                                         ~22, ->38
   44    37    >   ASSIGN                                                       !2, '%3C%3Fphp+%0A'
   46    38    >   ROPE_INIT                                         3  ~25     'echo+%27'
         39        ROPE_ADD                                          1  ~25     ~25, !1
         40        ROPE_END                                          2  ~24     ~25, '%27+.+PHP_EOL%3B'
         41        ASSIGN_OP                                         8          !2, ~24
   48    42        PRE_INC_OBJ                                                  'counter'
   50    43        VERIFY_RETURN_TYPE                                           !2
         44      > RETURN                                                       !2
   51    45*       VERIFY_RETURN_TYPE                                           
         46*     > RETURN                                                       null

End of function stream_read

Function stream_close:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gjHtc
function name:  stream_close
number of ops:  3
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   55     0  E > > RETURN                                                       <true>
   56     1*       VERIFY_RETURN_TYPE                                           
          2*     > RETURN                                                       null

End of function stream_close

Function stream_eof:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gjHtc
function name:  stream_eof
number of ops:  7
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   60     0  E >   FETCH_OBJ_R                                          ~0      'counter'
          1        FETCH_OBJ_R                                          ~1      'length'
          2        IS_IDENTICAL                                         ~2      ~0, ~1
          3        VERIFY_RETURN_TYPE                                           ~2
          4      > RETURN                                                       ~2
   61     5*       VERIFY_RETURN_TYPE                                           
          6*     > RETURN                                                       null

End of function stream_eof

Function stream_stat:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gjHtc
function name:  stream_stat
number of ops:  3
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   65     0  E > > RETURN                                                       <array>
   67     1*       VERIFY_RETURN_TYPE                                           
          2*     > RETURN                                                       null

End of function stream_stat

Function stream_set_option:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gjHtc
function name:  stream_set_option
number of ops:  5
compiled vars:  !0 = $option, !1 = $arg1, !2 = $arg2
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   69     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
   71     3      > RETURN                                                       <false>
   72     4*     > RETURN                                                       null

End of function stream_set_option

Function getsize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gjHtc
function name:  getSize
number of ops:  39
compiled vars:  !0 = $ret, !1 = $range, !2 = $numbers, !3 = $fizzOrBuzzs, !4 = $fizzbuzzs
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   76     0  E >   FETCH_OBJ_R                                          ~5      'length'
          1        MUL                                                  ~6      ~5, 18
          2        ADD                                                  ~7      7, ~6
          3        ASSIGN                                                       !0, ~7
   77     4        INIT_FCALL                                                   'range'
          5        SEND_VAL                                                     1
          6        FETCH_OBJ_R                                          ~9      'length'
          7        SEND_VAL                                                     ~9
          8        DO_ICALL                                             $10     
          9        ASSIGN                                                       !1, $10
   78    10        INIT_FCALL                                                   'array_filter'
         11        SEND_VAR                                                     !1
         12        DECLARE_LAMBDA_FUNCTION                              ~12     [0]
         13        SEND_VAL                                                     ~12
         14        DO_ICALL                                             $13     
         15        ASSIGN                                                       !2, $13
   79    16        FRAMELESS_ICALL_2                implode             ~15     '', !2
         17        STRLEN                                               ~16     ~15
         18        ASSIGN_OP                                         1          !0, ~16
   80    19        INIT_FCALL                                                   'array_filter'
         20        SEND_VAR                                                     !1
         21        DECLARE_LAMBDA_FUNCTION                              ~18     [1]
         22        SEND_VAL                                                     ~18
         23        DO_ICALL                                             $19     
         24        ASSIGN                                                       !3, $19
   81    25        COUNT                                                ~21     !3
         26        MUL                                                  ~22     ~21, 4
         27        ASSIGN_OP                                         1          !0, ~22
   82    28        INIT_FCALL                                                   'array_filter'
         29        SEND_VAR                                                     !1
         30        DECLARE_LAMBDA_FUNCTION                              ~24     [2]
         31        SEND_VAL                                                     ~24
         32        DO_ICALL                                             $25     
         33        ASSIGN                                                       !4, $25
   83    34        COUNT                                                ~27     !4
         35        MUL                                                  ~28     ~27, 8
         36        ASSIGN_OP                                         1          !0, ~28
   85    37      > RETURN                                                       !0
   86    38*     > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/gjHtc
function name:  {closure:FizzBuzzStreamWrapper::getSize():78}
number of ops:  9
compiled vars:  !0 = $n
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   78     0  E >   RECV                                                 !0      
          1        MOD                                                  ~1      !0, 3
          2        IS_NOT_IDENTICAL                                     ~2      ~1, 0
          3      > JMPZ_EX                                              ~2      ~2, ->7
          4    >   MOD                                                  ~3      !0, 5
          5        IS_NOT_IDENTICAL                                     ~4      ~3, 0
          6        BOOL                                                 ~2      ~4
          7    > > RETURN                                                       ~2
          8*     > RETURN                                                       null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
2 jumps found. (Code = 47) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
Branch analysis from position: 11
filename:       /in/gjHtc
function name:  {closure:FizzBuzzStreamWrapper::getSize():80}
number of ops:  13
compiled vars:  !0 = $n
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   80     0  E >   RECV                                                 !0      
          1        MOD                                                  ~1      !0, 15
          2        IS_NOT_IDENTICAL                                     ~2      ~1, 0
          3      > JMPZ_EX                                              ~2      ~2, ->11
          4    >   MOD                                                  ~3      !0, 3
          5        IS_IDENTICAL                                         ~4      ~3, 0
          6      > JMPNZ_EX                                             ~4      ~4, ->10
          7    >   MOD                                                  ~5      !0, 5
          8        IS_IDENTICAL                                         ~6      ~5, 0
          9        BOOL                                                 ~4      ~6
         10    >   BOOL                                                 ~2      ~4
         11    > > RETURN                                                       ~2
         12*     > RETURN                                                       null

End of Dynamic Function 1

Dynamic Function 2
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gjHtc
function name:  {closure:FizzBuzzStreamWrapper::getSize():82}
number of ops:  5
compiled vars:  !0 = $n
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   82     0  E >   RECV                                                 !0      
          1        MOD                                                  ~1      !0, 15
          2        IS_IDENTICAL                                         ~2      ~1, 0
          3      > RETURN                                                       ~2
          4*     > RETURN                                                       null

End of Dynamic Function 2

End of function getsize

End of class FizzBuzzStreamWrapper.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
154.5 ms | 1196 KiB | 13 Q