3v4l.org

run code in 500+ PHP versions simultaneously
<?php class NoConsumedFilter extends php_user_filter { function filter($in, $out, &$consumed, $closing) { while ($bucket = stream_bucket_make_writeable($in)) { // Do NOT update $consumed $bucket->data = strtoupper($bucket->data); stream_bucket_append($out, $bucket); } return PSFS_PASS_ON; } } class YesConsumedFilter extends php_user_filter { function filter($in, $out, &$consumed, $closing) { while ($bucket = stream_bucket_make_writeable($in)) { $consumed += $bucket->datalen; $bucket->data = strtoupper($bucket->data); stream_bucket_append($out, $bucket); } return PSFS_PASS_ON; } } stream_filter_register('no_consumed', 'NoConsumedFilter'); stream_filter_register('yes_consumed', 'YesConsumedFilter'); $filters = array('no_consumed', 'yes_consumed'); foreach ($filters as $filter) { $fp = tmpfile(); fwrite($fp, 'hello world'); rewind($fp); stream_filter_append($fp, $filter, STREAM_FILTER_READ); $data = fread($fp, 5); $pos = ftell($fp); $more = fread($fp, 100); $eof = feof($fp); echo $filter . ": first='" . $data . "' ftell=" . $pos . " rest='" . $more . "' eof=" . ($eof ? 'Y' : 'N') . "\n"; fclose($fp); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 62
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 62
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 54
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 62
filename:       /in/p9d8S
function name:  (null)
number of ops:  64
compiled vars:  !0 = $filters, !1 = $filter, !2 = $fp, !3 = $data, !4 = $pos, !5 = $more, !6 = $eof
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   29     0  E >   INIT_FCALL                                                   'stream_filter_register'
          1        SEND_VAL                                                     'no_consumed'
          2        SEND_VAL                                                     'NoConsumedFilter'
          3        DO_ICALL                                                     
   30     4        INIT_FCALL                                                   'stream_filter_register'
          5        SEND_VAL                                                     'yes_consumed'
          6        SEND_VAL                                                     'YesConsumedFilter'
          7        DO_ICALL                                                     
   32     8        ASSIGN                                                       !0, <array>
   34     9      > FE_RESET_R                                           $10     !0, ->62
         10    > > FE_FETCH_R                                                   $10, !1, ->62
   35    11    >   INIT_FCALL                                                   'tmpfile'
         12        DO_ICALL                                             $11     
         13        ASSIGN                                                       !2, $11
   36    14        INIT_FCALL                                                   'fwrite'
         15        SEND_VAR                                                     !2
         16        SEND_VAL                                                     'hello+world'
         17        DO_ICALL                                                     
   37    18        INIT_FCALL                                                   'rewind'
         19        SEND_VAR                                                     !2
         20        DO_ICALL                                                     
   39    21        INIT_FCALL                                                   'stream_filter_append'
         22        SEND_VAR                                                     !2
         23        SEND_VAR                                                     !1
         24        SEND_VAL                                                     1
         25        DO_ICALL                                                     
   41    26        INIT_FCALL                                                   'fread'
         27        SEND_VAR                                                     !2
         28        SEND_VAL                                                     5
         29        DO_ICALL                                             $16     
         30        ASSIGN                                                       !3, $16
   42    31        INIT_FCALL                                                   'ftell'
         32        SEND_VAR                                                     !2
         33        DO_ICALL                                             $18     
         34        ASSIGN                                                       !4, $18
   43    35        INIT_FCALL                                                   'fread'
         36        SEND_VAR                                                     !2
         37        SEND_VAL                                                     100
         38        DO_ICALL                                             $20     
         39        ASSIGN                                                       !5, $20
   44    40        INIT_FCALL                                                   'feof'
         41        SEND_VAR                                                     !2
         42        DO_ICALL                                             $22     
         43        ASSIGN                                                       !6, $22
   46    44        CONCAT                                               ~24     !1, '%3A+first%3D%27'
         45        CONCAT                                               ~25     ~24, !3
         46        CONCAT                                               ~26     ~25, '%27+ftell%3D'
         47        CONCAT                                               ~27     ~26, !4
         48        CONCAT                                               ~28     ~27, '+rest%3D%27'
         49        CONCAT                                               ~29     ~28, !5
         50        CONCAT                                               ~30     ~29, '%27+eof%3D'
         51      > JMPZ                                                         !6, ->54
         52    >   QM_ASSIGN                                            ~31     'Y'
         53      > JMP                                                          ->55
         54    >   QM_ASSIGN                                            ~31     'N'
         55    >   CONCAT                                               ~32     ~30, ~31
         56        CONCAT                                               ~33     ~32, '%0A'
         57        ECHO                                                         ~33
   48    58        INIT_FCALL                                                   'fclose'
         59        SEND_VAR                                                     !2
         60        DO_ICALL                                                     
   34    61      > JMP                                                          ->10
         62    >   FE_FREE                                                      $10
   49    63      > RETURN                                                       1

Class NoConsumedFilter:
Function filter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 5
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 5
Branch analysis from position: 20
Branch analysis from position: 5
filename:       /in/p9d8S
function name:  filter
number of ops:  22
compiled vars:  !0 = $in, !1 = $out, !2 = $consumed, !3 = $closing, !4 = $bucket
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
          3        RECV                                                 !3      
    7     4      > JMP                                                          ->15
    9     5    >   INIT_FCALL                                                   'strtoupper'
          6        FETCH_OBJ_R                                          ~6      !4, 'data'
          7        SEND_VAL                                                     ~6
          8        DO_ICALL                                             $7      
          9        ASSIGN_OBJ                                                   !4, 'data'
         10        OP_DATA                                                      $7
   10    11        INIT_FCALL                                                   'stream_bucket_append'
         12        SEND_VAR                                                     !1
         13        SEND_VAR                                                     !4
         14        DO_ICALL                                                     
    7    15    >   INIT_FCALL                                                   'stream_bucket_make_writeable'
         16        SEND_VAR                                                     !0
         17        DO_ICALL                                             $9      
         18        ASSIGN                                               ~10     !4, $9
         19      > JMPNZ                                                        ~10, ->5
   12    20    > > RETURN                                                       2
   13    21*     > RETURN                                                       null

End of function filter

End of class NoConsumedFilter.

Class YesConsumedFilter:
Function filter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 5
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 5
Branch analysis from position: 22
Branch analysis from position: 5
filename:       /in/p9d8S
function name:  filter
number of ops:  24
compiled vars:  !0 = $in, !1 = $out, !2 = $consumed, !3 = $closing, !4 = $bucket
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      > JMP                                                          ->17
   21     5    >   FETCH_OBJ_R                                          ~5      !4, 'datalen'
          6        ASSIGN_OP                                         1          !2, ~5
   22     7        INIT_FCALL                                                   'strtoupper'
          8        FETCH_OBJ_R                                          ~8      !4, 'data'
          9        SEND_VAL                                                     ~8
         10        DO_ICALL                                             $9      
         11        ASSIGN_OBJ                                                   !4, 'data'
         12        OP_DATA                                                      $9
   23    13        INIT_FCALL                                                   'stream_bucket_append'
         14        SEND_VAR                                                     !1
         15        SEND_VAR                                                     !4
         16        DO_ICALL                                                     
   20    17    >   INIT_FCALL                                                   'stream_bucket_make_writeable'
         18        SEND_VAR                                                     !0
         19        DO_ICALL                                             $11     
         20        ASSIGN                                               ~12     !4, $11
         21      > JMPNZ                                                        ~12, ->5
   25    22    > > RETURN                                                       2
   26    23*     > RETURN                                                       null

End of function filter

End of class YesConsumedFilter.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
165.26 ms | 2903 KiB | 20 Q