3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); set_time_limit(1); stream_wrapper_register('fizzbuzz', FizzBuzzStreamWrapper::class); require 'fizzbuzz://3'; 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 { echo 'called `' . __METHOD__ . '` with ' . json_encode(func_get_args()) . PHP_EOL; 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 { echo 'called `' . __METHOD__ . '` with ' . json_encode(func_get_args()) . PHP_EOL; echo "\tcurrent counter: {$this->counter}" . PHP_EOL; $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 { echo 'called `' . __METHOD__ . '` with ' . json_encode(func_get_args()) . PHP_EOL; return true; } public function stream_eof(): bool { echo 'called `' . __METHOD__ . '` with ' . json_encode(func_get_args()) . PHP_EOL; echo "\tcurrent counter: {$this->counter}" . PHP_EOL; return $this->counter ===$this->length; } public function stream_stat(): array|false { echo 'called `' . __METHOD__ . '` with ' . json_encode(func_get_args()) . PHP_EOL; return ['size' => $this->getSize()]; } public function stream_set_option(int $option, int $arg1, int $arg2) { echo 'called `' . __METHOD__ . '` with ' . json_encode(func_get_args()) . PHP_EOL; 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/vNfpt
function name:  (null)
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   INIT_FCALL                                               'set_time_limit'
          1        SEND_VAL                                                 1
          2        DO_ICALL                                                 
    6     3        INIT_FCALL                                               'stream_wrapper_register'
          4        SEND_VAL                                                 'fizzbuzz'
          5        SEND_VAL                                                 'FizzBuzzStreamWrapper'
          6        DO_ICALL                                                 
    7     7        INCLUDE_OR_EVAL                                          'fizzbuzz%3A%2F%2F3', REQUIRE
   83     8      > 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/vNfpt
function name:  stream_open
number of ops:  29
compiled vars:  !0 = $path, !1 = $mode, !2 = $options, !3 = $opened_path, !4 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   18     4        INIT_FCALL                                               'json_encode'
          5        FUNC_GET_ARGS                                    ~5      
          6        SEND_VAL                                                 ~5
          7        DO_ICALL                                         $6      
          8        CONCAT                                           ~7      'called+%60FizzBuzzStreamWrapper%3A%3Astream_open%60+with+', $6
          9        CONCAT                                           ~8      ~7, '%0A'
         10        ECHO                                                     ~8
   19    11        INIT_FCALL                                               'preg_match'
         12        SEND_VAL                                                 '%23%28%5B%5Cd%5D%2B%24%29%23'
         13        SEND_VAR                                                 !0
         14        SEND_REF                                                 !4
         15        DO_ICALL                                                 
   20    16        INIT_FCALL                                               'filter_var'
   21    17        FETCH_DIM_IS                                     ~11     !4, 1
         18        COALESCE                                         ~12     ~11
         19        QM_ASSIGN                                        ~12     ''
         20        SEND_VAL                                                 ~12
   22    21        SEND_VAL                                                 257
   23    22        SEND_VAL                                                 <array>
   20    23        DO_ICALL                                         $13     
         24        ASSIGN_OBJ                                               'length'
   23    25        OP_DATA                                                  $13
   26    26      > RETURN                                                   <true>
   27    27*       VERIFY_RETURN_TYPE                                       
         28*     > RETURN                                                   null

End of function stream_open

Function stream_read:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 29
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 31
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 33
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 45
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
filename:       /in/vNfpt
function name:  stream_read
number of ops:  54
compiled vars:  !0 = $count, !1 = $fizzbuzz, !2 = $contents
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
   30     1        INIT_FCALL                                               'json_encode'
          2        FUNC_GET_ARGS                                    ~3      
          3        SEND_VAL                                                 ~3
          4        DO_ICALL                                         $4      
          5        CONCAT                                           ~5      'called+%60FizzBuzzStreamWrapper%3A%3Astream_read%60+with+', $4
          6        CONCAT                                           ~6      ~5, '%0A'
          7        ECHO                                                     ~6
   31     8        NOP                                                      
          9        FETCH_OBJ_R                                      ~7      'counter'
         10        FAST_CONCAT                                      ~8      '%09current+counter%3A+', ~7
         11        CONCAT                                           ~9      ~8, '%0A'
         12        ECHO                                                     ~9
   33    13        FETCH_OBJ_R                                      ~11     'counter'
         14        MOD                                              ~12     ~11, 15
         15        IS_IDENTICAL                                     ~13     ~12, 0
         16        IS_IDENTICAL                                             ~13, <true>
         17      > JMPNZ                                                    ~10, ->29
   34    18    >   FETCH_OBJ_R                                      ~14     'counter'
         19        MOD                                              ~15     ~14, 5
         20        IS_IDENTICAL                                     ~16     ~15, 0
         21        IS_IDENTICAL                                             ~16, <true>
         22      > JMPNZ                                                    ~10, ->31
   35    23    >   FETCH_OBJ_R                                      ~17     'counter'
         24        MOD                                              ~18     ~17, 3
         25        IS_IDENTICAL                                     ~19     ~18, 0
         26        IS_IDENTICAL                                             ~19, <true>
         27      > JMPNZ                                                    ~10, ->33
         28    > > JMP                                                      ->35
   33    29    >   QM_ASSIGN                                        ~20     'FizzBuzz'
         30      > JMP                                                      ->39
   34    31    >   QM_ASSIGN                                        ~20     'Buzz'
         32      > JMP                                                      ->39
   35    33    >   QM_ASSIGN                                        ~20     'Fizz'
         34      > JMP                                                      ->39
   36    35    >   FETCH_OBJ_R                                      ~21     'counter'
         36        CAST                                          6  ~22     ~21
         37        QM_ASSIGN                                        ~20     ~22
         38      > JMP                                                      ->39
   32    39    >   ASSIGN                                                   !1, ~20
   38    40        ASSIGN                                                   !2, ''
   39    41        FETCH_OBJ_R                                      ~25     'counter'
         42        IS_IDENTICAL                                             ~25, 1
         43      > JMPZ                                                     ~26, ->45
   40    44    >   ASSIGN                                                   !2, '%3C%3Fphp+%0A'
   42    45    >   ROPE_INIT                                     3  ~29     'echo+%27'
         46        ROPE_ADD                                      1  ~29     ~29, !1
         47        ROPE_END                                      2  ~28     ~29, '%27+.+PHP_EOL%3B'
         48        ASSIGN_OP                                     8          !2, ~28
   44    49        PRE_INC_OBJ                                              'counter'
   46    50        VERIFY_RETURN_TYPE                                       !2
         51      > RETURN                                                   !2
   47    52*       VERIFY_RETURN_TYPE                                       
         53*     > 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/vNfpt
function name:  stream_close
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   INIT_FCALL                                               'json_encode'
          1        FUNC_GET_ARGS                                    ~0      
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4        CONCAT                                           ~2      'called+%60FizzBuzzStreamWrapper%3A%3Astream_close%60+with+', $1
          5        CONCAT                                           ~3      ~2, '%0A'
          6        ECHO                                                     ~3
   51     7      > RETURN                                                   <true>
   52     8*       VERIFY_RETURN_TYPE                                       
          9*     > 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/vNfpt
function name:  stream_eof
number of ops:  19
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   INIT_FCALL                                               'json_encode'
          1        FUNC_GET_ARGS                                    ~0      
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4        CONCAT                                           ~2      'called+%60FizzBuzzStreamWrapper%3A%3Astream_eof%60+with+', $1
          5        CONCAT                                           ~3      ~2, '%0A'
          6        ECHO                                                     ~3
   56     7        NOP                                                      
          8        FETCH_OBJ_R                                      ~4      'counter'
          9        FAST_CONCAT                                      ~5      '%09current+counter%3A+', ~4
         10        CONCAT                                           ~6      ~5, '%0A'
         11        ECHO                                                     ~6
   57    12        FETCH_OBJ_R                                      ~7      'counter'
         13        FETCH_OBJ_R                                      ~8      'length'
         14        IS_IDENTICAL                                     ~9      ~7, ~8
         15        VERIFY_RETURN_TYPE                                       ~9
         16      > RETURN                                                   ~9
   58    17*       VERIFY_RETURN_TYPE                                       
         18*     > 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/vNfpt
function name:  stream_stat
number of ops:  14
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   INIT_FCALL                                               'json_encode'
          1        FUNC_GET_ARGS                                    ~0      
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4        CONCAT                                           ~2      'called+%60FizzBuzzStreamWrapper%3A%3Astream_stat%60+with+', $1
          5        CONCAT                                           ~3      ~2, '%0A'
          6        ECHO                                                     ~3
   63     7        INIT_METHOD_CALL                                         'getSize'
          8        DO_FCALL                                      0  $4      
          9        INIT_ARRAY                                       ~5      $4, 'size'
         10        VERIFY_RETURN_TYPE                                       ~5
         11      > RETURN                                                   ~5
   64    12*       VERIFY_RETURN_TYPE                                       
         13*     > 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/vNfpt
function name:  stream_set_option
number of ops:  12
compiled vars:  !0 = $option, !1 = $arg1, !2 = $arg2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   67     3        INIT_FCALL                                               'json_encode'
          4        FUNC_GET_ARGS                                    ~3      
          5        SEND_VAL                                                 ~3
          6        DO_ICALL                                         $4      
          7        CONCAT                                           ~5      'called+%60FizzBuzzStreamWrapper%3A%3Astream_set_option%60+with+', $4
          8        CONCAT                                           ~6      ~5, '%0A'
          9        ECHO                                                     ~6
   68    10      > RETURN                                                   <false>
   69    11*     > 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/vNfpt
function name:  getSize
number of ops:  42
compiled vars:  !0 = $ret, !1 = $range, !2 = $numbers, !3 = $fizzOrBuzzs, !4 = $fizzbuzzs
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   72     0  E >   FETCH_OBJ_R                                      ~5      'length'
          1        MUL                                              ~6      ~5, 18
          2        ADD                                              ~7      7, ~6
          3        ASSIGN                                                   !0, ~7
   73     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
   74    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
   75    16        INIT_FCALL                                               'implode'
         17        SEND_VAL                                                 ''
         18        SEND_VAR                                                 !2
         19        DO_ICALL                                         $15     
         20        STRLEN                                           ~16     $15
         21        ASSIGN_OP                                     1          !0, ~16
   76    22        INIT_FCALL                                               'array_filter'
         23        SEND_VAR                                                 !1
         24        DECLARE_LAMBDA_FUNCTION                          ~18     [1]
         25        SEND_VAL                                                 ~18
         26        DO_ICALL                                         $19     
         27        ASSIGN                                                   !3, $19
   77    28        COUNT                                            ~21     !3
         29        MUL                                              ~22     ~21, 4
         30        ASSIGN_OP                                     1          !0, ~22
   78    31        INIT_FCALL                                               'array_filter'
         32        SEND_VAR                                                 !1
         33        DECLARE_LAMBDA_FUNCTION                          ~24     [2]
         34        SEND_VAL                                                 ~24
         35        DO_ICALL                                         $25     
         36        ASSIGN                                                   !4, $25
   79    37        COUNT                                            ~27     !4
         38        MUL                                              ~28     ~27, 8
         39        ASSIGN_OP                                     1          !0, ~28
   81    40      > RETURN                                                   !0
   82    41*     > 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/vNfpt
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $n
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   74     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/vNfpt
function name:  {closure}
number of ops:  13
compiled vars:  !0 = $n
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   76     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/vNfpt
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $n
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   78     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.0.0


preferences:
140.87 ms | 1026 KiB | 21 Q