3v4l.org

run code in 500+ PHP versions simultaneously
<?php class File_stream { static $stream; protected $position; public $context; function stream_open ($path, $mode) { if ($mode != 'r' && $mode != 'rb') { return false; } $this->position = 0; return true; } function stream_read ($length) { fseek(self::$stream, $this->position); $bytes = fread(self::$stream, $length); $this->position += strlen($bytes); return $bytes; } function stream_tell () { return $this->position; } function stream_eof () { fseek(self::$stream, $this->position); return feof(self::$stream); } function stream_seek ($offset, $whence = SEEK_SET) { var_dump('seek', $this->position, $offset, $whence); fseek(self::$stream, $this->position); $result = fseek(self::$stream, $offset, $whence); $this->position = ftell(self::$stream); return $result === 0; } function stream_stat () { return fstat(self::$stream); } } stream_wrapper_register('request-file', 'File_stream'); $data = '0123456789abcdef'; $stream_direct = fopen('php://temp', 'w+b'); fwrite($stream_direct, $data); rewind($stream_direct); File_stream::$stream = $stream_direct; $stream = fopen('request-file://', 'r'); var_dump(fread($stream, 3)); var_dump(ftell($stream)); var_dump(fseek($stream, -1, SEEK_CUR)); var_dump(fread($stream, 2)); var_dump(ftell($stream)); fclose($stream);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/baAsV
function name:  (null)
number of ops:  62
compiled vars:  !0 = $data, !1 = $stream_direct, !2 = $stream
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   38     0  E >   INIT_FCALL                                                   'stream_wrapper_register'
          1        SEND_VAL                                                     'request-file'
          2        SEND_VAL                                                     'File_stream'
          3        DO_ICALL                                                     
   40     4        ASSIGN                                                       !0, '0123456789abcdef'
   41     5        INIT_FCALL                                                   'fopen'
          6        SEND_VAL                                                     'php%3A%2F%2Ftemp'
          7        SEND_VAL                                                     'w%2Bb'
          8        DO_ICALL                                             $5      
          9        ASSIGN                                                       !1, $5
   42    10        INIT_FCALL                                                   'fwrite'
         11        SEND_VAR                                                     !1
         12        SEND_VAR                                                     !0
         13        DO_ICALL                                                     
   43    14        INIT_FCALL                                                   'rewind'
         15        SEND_VAR                                                     !1
         16        DO_ICALL                                                     
   45    17        ASSIGN_STATIC_PROP                                           'stream', 'File_stream'
         18        OP_DATA                                                      !1
   47    19        INIT_FCALL                                                   'fopen'
         20        SEND_VAL                                                     'request-file%3A%2F%2F'
         21        SEND_VAL                                                     'r'
         22        DO_ICALL                                             $10     
         23        ASSIGN                                                       !2, $10
   48    24        INIT_FCALL                                                   'var_dump'
         25        INIT_FCALL                                                   'fread'
         26        SEND_VAR                                                     !2
         27        SEND_VAL                                                     3
         28        DO_ICALL                                             $12     
         29        SEND_VAR                                                     $12
         30        DO_ICALL                                                     
   49    31        INIT_FCALL                                                   'var_dump'
         32        INIT_FCALL                                                   'ftell'
         33        SEND_VAR                                                     !2
         34        DO_ICALL                                             $14     
         35        SEND_VAR                                                     $14
         36        DO_ICALL                                                     
   50    37        INIT_FCALL                                                   'var_dump'
         38        INIT_FCALL                                                   'fseek'
         39        SEND_VAR                                                     !2
         40        SEND_VAL                                                     -1
         41        SEND_VAL                                                     1
         42        DO_ICALL                                             $16     
         43        SEND_VAR                                                     $16
         44        DO_ICALL                                                     
   51    45        INIT_FCALL                                                   'var_dump'
         46        INIT_FCALL                                                   'fread'
         47        SEND_VAR                                                     !2
         48        SEND_VAL                                                     2
         49        DO_ICALL                                             $18     
         50        SEND_VAR                                                     $18
         51        DO_ICALL                                                     
   52    52        INIT_FCALL                                                   'var_dump'
         53        INIT_FCALL                                                   'ftell'
         54        SEND_VAR                                                     !2
         55        DO_ICALL                                             $20     
         56        SEND_VAR                                                     $20
         57        DO_ICALL                                                     
   53    58        INIT_FCALL                                                   'fclose'
         59        SEND_VAR                                                     !2
         60        DO_ICALL                                                     
         61      > RETURN                                                       1

Class File_stream:
Function stream_open:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/baAsV
function name:  stream_open
number of ops:  12
compiled vars:  !0 = $path, !1 = $mode
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
    8     2        IS_NOT_EQUAL                                         ~2      !1, 'r'
          3      > JMPZ_EX                                              ~2      ~2, ->6
          4    >   IS_NOT_EQUAL                                         ~3      !1, 'rb'
          5        BOOL                                                 ~2      ~3
          6    > > JMPZ                                                         ~2, ->8
    9     7    > > RETURN                                                       <false>
   11     8    >   ASSIGN_OBJ                                                   'position'
          9        OP_DATA                                                      0
   12    10      > RETURN                                                       <true>
   13    11*     > RETURN                                                       null

End of function stream_open

Function stream_read:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/baAsV
function name:  stream_read
number of ops:  18
compiled vars:  !0 = $length, !1 = $bytes
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   RECV                                                 !0      
   15     1        INIT_FCALL                                                   'fseek'
          2        FETCH_STATIC_PROP_R              global lock         ~2      'stream'
          3        SEND_VAL                                                     ~2
          4        FETCH_OBJ_R                                          ~3      'position'
          5        SEND_VAL                                                     ~3
          6        DO_ICALL                                                     
   16     7        INIT_FCALL                                                   'fread'
          8        FETCH_STATIC_PROP_R              unknown             ~5      'stream'
          9        SEND_VAL                                                     ~5
         10        SEND_VAR                                                     !0
         11        DO_ICALL                                             $6      
         12        ASSIGN                                                       !1, $6
   17    13        STRLEN                                               ~9      !1
         14        ASSIGN_OBJ_OP                                     1          'position'
         15        OP_DATA                                                      ~9
   18    16      > RETURN                                                       !1
   19    17*     > RETURN                                                       null

End of function stream_read

Function stream_tell:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/baAsV
function name:  stream_tell
number of ops:  3
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   21     0  E >   FETCH_OBJ_R                                          ~0      'position'
          1      > RETURN                                                       ~0
   22     2*     > RETURN                                                       null

End of function stream_tell

Function stream_eof:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/baAsV
function name:  stream_eof
number of ops:  12
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   24     0  E >   INIT_FCALL                                                   'fseek'
          1        FETCH_STATIC_PROP_R              global lock         ~0      'stream'
          2        SEND_VAL                                                     ~0
          3        FETCH_OBJ_R                                          ~1      'position'
          4        SEND_VAL                                                     ~1
          5        DO_ICALL                                                     
   25     6        INIT_FCALL                                                   'feof'
          7        FETCH_STATIC_PROP_R              unknown             ~3      'stream'
          8        SEND_VAL                                                     ~3
          9        DO_ICALL                                             $4      
         10      > RETURN                                                       $4
   26    11*     > RETURN                                                       null

End of function stream_eof

Function stream_seek:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/baAsV
function name:  stream_seek
number of ops:  31
compiled vars:  !0 = $offset, !1 = $whence, !2 = $result
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   27     0  E >   RECV                                                 !0      
          1        RECV_INIT                                            !1      <const ast>
   28     2        INIT_FCALL                                                   'var_dump'
          3        SEND_VAL                                                     'seek'
          4        FETCH_OBJ_R                                          ~3      'position'
          5        SEND_VAL                                                     ~3
          6        SEND_VAR                                                     !0
          7        SEND_VAR                                                     !1
          8        DO_ICALL                                                     
   29     9        INIT_FCALL                                                   'fseek'
         10        FETCH_STATIC_PROP_R              unknown             ~5      'stream'
         11        SEND_VAL                                                     ~5
         12        FETCH_OBJ_R                                          ~6      'position'
         13        SEND_VAL                                                     ~6
         14        DO_ICALL                                                     
   30    15        INIT_FCALL                                                   'fseek'
         16        FETCH_STATIC_PROP_R              unknown             ~8      'stream'
         17        SEND_VAL                                                     ~8
         18        SEND_VAR                                                     !0
         19        SEND_VAR                                                     !1
         20        DO_ICALL                                             $9      
         21        ASSIGN                                                       !2, $9
   31    22        INIT_FCALL                                                   'ftell'
         23        FETCH_STATIC_PROP_R              unknown             ~12     'stream'
         24        SEND_VAL                                                     ~12
         25        DO_ICALL                                             $13     
         26        ASSIGN_OBJ                                                   'position'
         27        OP_DATA                                                      $13
   32    28        IS_IDENTICAL                                         ~14     !2, 0
         29      > RETURN                                                       ~14
   33    30*     > RETURN                                                       null

End of function stream_seek

Function stream_stat:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/baAsV
function name:  stream_stat
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   35     0  E >   INIT_FCALL                                                   'fstat'
          1        FETCH_STATIC_PROP_R              global lock         ~0      'stream'
          2        SEND_VAL                                                     ~0
          3        DO_ICALL                                             $1      
          4      > RETURN                                                       $1
   36     5*     > RETURN                                                       null

End of function stream_stat

End of class File_stream.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
165.62 ms | 1744 KiB | 24 Q