3v4l.org

run code in 300+ PHP versions simultaneously
<?php class File_stream { static $stream; protected $position; 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; } 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/3RG7r
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
-------------------------------------------------------------------------------------
   37     0  E >   INIT_FCALL                                               'stream_wrapper_register'
          1        SEND_VAL                                                 'request-file'
          2        SEND_VAL                                                 'File_stream'
          3        DO_ICALL                                                 
   39     4        ASSIGN                                                   !0, '0123456789abcdef'
   40     5        INIT_FCALL                                               'fopen'
          6        SEND_VAL                                                 'php%3A%2F%2Ftemp'
          7        SEND_VAL                                                 'w%2Bb'
          8        DO_ICALL                                         $5      
          9        ASSIGN                                                   !1, $5
   41    10        INIT_FCALL                                               'fwrite'
         11        SEND_VAR                                                 !1
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                                 
   42    14        INIT_FCALL                                               'rewind'
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                                 
   44    17        ASSIGN_STATIC_PROP                                       'stream', 'File_stream'
         18        OP_DATA                                                  !1
   46    19        INIT_FCALL                                               'fopen'
         20        SEND_VAL                                                 'request-file%3A%2F%2F'
         21        SEND_VAL                                                 'r'
         22        DO_ICALL                                         $10     
         23        ASSIGN                                                   !2, $10
   47    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                                                 
   48    31        INIT_FCALL                                               'var_dump'
         32        INIT_FCALL                                               'ftell'
         33        SEND_VAR                                                 !2
         34        DO_ICALL                                         $14     
         35        SEND_VAR                                                 $14
         36        DO_ICALL                                                 
   49    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                                                 
   50    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                                                 
   51    52        INIT_FCALL                                               'var_dump'
         53        INIT_FCALL                                               'ftell'
         54        SEND_VAR                                                 !2
         55        DO_ICALL                                         $20     
         56        SEND_VAR                                                 $20
         57        DO_ICALL                                                 
   52    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/3RG7r
function name:  stream_open
number of ops:  12
compiled vars:  !0 = $path, !1 = $mode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     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
    8     7    > > RETURN                                                   <false>
   10     8    >   ASSIGN_OBJ                                               'position'
          9        OP_DATA                                                  0
   11    10      > RETURN                                                   <true>
   12    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/3RG7r
function name:  stream_read
number of ops:  18
compiled vars:  !0 = $length, !1 = $bytes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   14     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                                                 
   15     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
   16    13        STRLEN                                           ~9      !1
         14        ASSIGN_OBJ_OP                                 1          'position'
         15        OP_DATA                                                  ~9
   17    16      > RETURN                                                   !1
   18    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/3RG7r
function name:  stream_tell
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   FETCH_OBJ_R                                      ~0      'position'
          1      > RETURN                                                   ~0
   21     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/3RG7r
function name:  stream_eof
number of ops:  12
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     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                                                 
   24     6        INIT_FCALL                                               'feof'
          7        FETCH_STATIC_PROP_R          unknown             ~3      'stream'
          8        SEND_VAL                                                 ~3
          9        DO_ICALL                                         $4      
         10      > RETURN                                                   $4
   25    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/3RG7r
function name:  stream_seek
number of ops:  30
compiled vars:  !0 = $offset, !1 = $whence, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <const ast>
   27     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                                                 
   28     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                                                 
   29    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
   30    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
   31    28      > RETURN                                                   !2
   32    29*     > 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/3RG7r
function name:  stream_stat
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     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
   35     5*     > RETURN                                                   null

End of function stream_stat

End of class File_stream.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.39 ms | 1408 KiB | 35 Q