3v4l.org

run code in 500+ PHP versions simultaneously
<?php class MyFilter extends php_user_filter { private $data = ''; public function filter($in, $out, &$consumed, $closing) { $return = PSFS_FEED_ME; // While input data is available, continue to read it. while ($bucket_in = stream_bucket_make_writeable($in)) { $this->data .= $bucket_in->data; $consumed += $bucket_in->datalen; // Process whole lines. while (preg_match('/(.*?)[\r\n]+(.*)/s', $this->data, $match) === 1) { list(, $data, $this->data) = $match; // Send this record output. $data = strrev($data) . PHP_EOL; $bucket_out = stream_bucket_new($this->stream, $data); $return = PSFS_PASS_ON; stream_bucket_append($out, $bucket_out); } } // Process the final line. if ($closing && $this->data !== '') { $data = strrev($this->data) . PHP_EOL; $bucket_out = stream_bucket_new($this->stream, $data); $return = PSFS_PASS_ON; stream_bucket_append($out, $bucket_out); } return $return; } } stream_filter_register('my-filter', 'MyFilter'); $input = "Line one\nLine two\nLine three"; $stream = fopen('data://text/plain,' . $input, 'r'); stream_filter_append($stream, 'my-filter'); $output = ''; while (!feof($stream)) { $output .= fread($stream, 16); } fclose($stream); echo $output;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 17
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 17
Branch analysis from position: 27
Branch analysis from position: 17
filename:       /in/kaeRJ
function name:  (null)
number of ops:  32
compiled vars:  !0 = $input, !1 = $stream, !2 = $output
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   36     0  E >   INIT_FCALL                                                   'stream_filter_register'
          1        SEND_VAL                                                     'my-filter'
          2        SEND_VAL                                                     'MyFilter'
          3        DO_ICALL                                                     
   38     4        ASSIGN                                                       !0, 'Line+one%0ALine+two%0ALine+three'
   40     5        INIT_FCALL                                                   'fopen'
          6        CONCAT                                               ~5      'data%3A%2F%2Ftext%2Fplain%2C', !0
          7        SEND_VAL                                                     ~5
          8        SEND_VAL                                                     'r'
          9        DO_ICALL                                             $6      
         10        ASSIGN                                                       !1, $6
   41    11        INIT_FCALL                                                   'stream_filter_append'
         12        SEND_VAR                                                     !1
         13        SEND_VAL                                                     'my-filter'
         14        DO_ICALL                                                     
   43    15        ASSIGN                                                       !2, ''
   44    16      > JMP                                                          ->22
   45    17    >   INIT_FCALL                                                   'fread'
         18        SEND_VAR                                                     !1
         19        SEND_VAL                                                     16
         20        DO_ICALL                                             $10     
         21        ASSIGN_OP                                         8          !2, $10
   44    22    >   INIT_FCALL                                                   'feof'
         23        SEND_VAR                                                     !1
         24        DO_ICALL                                             $12     
         25        BOOL_NOT                                             ~13     $12
         26      > JMPNZ                                                        ~13, ->17
   47    27    >   INIT_FCALL                                                   'fclose'
         28        SEND_VAR                                                     !1
         29        DO_ICALL                                                     
   49    30        ECHO                                                         !2
   50    31      > RETURN                                                       1

Class MyFilter:
Function filter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
2 jumps found. (Code = 44) Position 1 = 48, Position 2 = 6
Branch analysis from position: 48
2 jumps found. (Code = 46) Position 1 = 49, Position 2 = 52
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 70
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 70
Branch analysis from position: 52
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 12
Branch analysis from position: 43
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 12
Branch analysis from position: 43
Branch analysis from position: 12
filename:       /in/kaeRJ
function name:  filter
number of ops:  72
compiled vars:  !0 = $in, !1 = $out, !2 = $consumed, !3 = $closing, !4 = $return, !5 = $bucket_in, !6 = $match, !7 = $data, !8 = $bucket_out
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
          3        RECV                                                 !3      
    6     4        ASSIGN                                                       !4, 1
    9     5      > JMP                                                          ->43
   10     6    >   FETCH_OBJ_R                                          ~11     !5, 'data'
          7        ASSIGN_OBJ_OP                                     8          'data'
          8        OP_DATA                                                      ~11
   11     9        FETCH_OBJ_R                                          ~12     !5, 'datalen'
         10        ASSIGN_OP                                         1          !2, ~12
   14    11      > JMP                                                          ->35
   15    12    >   QM_ASSIGN                                            ~14     !6
         13        FETCH_LIST_R                                         $15     ~14, 1
         14        ASSIGN                                                       !7, $15
         15        FETCH_LIST_R                                         $17     ~14, 2
         16        ASSIGN_OBJ                                                   'data'
         17        OP_DATA                                                      $17
         18        FREE                                                         ~14
   17    19        INIT_FCALL                                                   'strrev'
         20        SEND_VAR                                                     !7
         21        DO_ICALL                                             $19     
         22        CONCAT                                               ~20     $19, '%0A'
         23        ASSIGN                                                       !7, ~20
   18    24        INIT_FCALL                                                   'stream_bucket_new'
         25        FETCH_OBJ_R                                          ~22     'stream'
         26        SEND_VAL                                                     ~22
         27        SEND_VAR                                                     !7
         28        DO_ICALL                                             $23     
         29        ASSIGN                                                       !8, $23
   19    30        ASSIGN                                                       !4, 2
   20    31        INIT_FCALL                                                   'stream_bucket_append'
         32        SEND_VAR                                                     !1
         33        SEND_VAR                                                     !8
         34        DO_ICALL                                                     
   14    35    >   INIT_FCALL                                                   'preg_match'
         36        SEND_VAL                                                     '%2F%28.%2A%3F%29%5B%5Cr%5Cn%5D%2B%28.%2A%29%2Fs'
         37        FETCH_OBJ_R                                          ~27     'data'
         38        SEND_VAL                                                     ~27
         39        SEND_REF                                                     !6
         40        DO_ICALL                                             $28     
         41        IS_IDENTICAL                                                 $28, 1
         42      > JMPNZ                                                        ~29, ->12
    9    43    >   INIT_FCALL                                                   'stream_bucket_make_writeable'
         44        SEND_VAR                                                     !0
         45        DO_ICALL                                             $30     
         46        ASSIGN                                               ~31     !5, $30
         47      > JMPNZ                                                        ~31, ->6
   25    48    > > JMPZ_EX                                              ~32     !3, ->52
         49    >   FETCH_OBJ_R                                          ~33     'data'
         50        IS_NOT_IDENTICAL                                     ~34     ~33, ''
         51        BOOL                                                 ~32     ~34
         52    > > JMPZ                                                         ~32, ->70
   26    53    >   INIT_FCALL                                                   'strrev'
         54        FETCH_OBJ_R                                          ~35     'data'
         55        SEND_VAL                                                     ~35
         56        DO_ICALL                                             $36     
         57        CONCAT                                               ~37     $36, '%0A'
         58        ASSIGN                                                       !7, ~37
   27    59        INIT_FCALL                                                   'stream_bucket_new'
         60        FETCH_OBJ_R                                          ~39     'stream'
         61        SEND_VAL                                                     ~39
         62        SEND_VAR                                                     !7
         63        DO_ICALL                                             $40     
         64        ASSIGN                                                       !8, $40
   28    65        ASSIGN                                                       !4, 2
   29    66        INIT_FCALL                                                   'stream_bucket_append'
         67        SEND_VAR                                                     !1
         68        SEND_VAR                                                     !8
         69        DO_ICALL                                                     
   32    70    > > RETURN                                                       !4
   33    71*     > RETURN                                                       null

End of function filter

End of class MyFilter.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
214.01 ms | 2640 KiB | 24 Q