3v4l.org

run code in 300+ PHP versions simultaneously
<?php class File_stream { static $stream; public $context; private $_position; public function __get($name) { $n = "_" . $name; echo " get {$name} = {$this->$n}\n"; return $this->$n; } public function __set($name, $value) { $n = "_" . $name; echo " set {$name} = {$value}\n"; $this->$n = $value; } function stream_open ($path, $mode) { echo " open\n"; if ($mode != 'r' && $mode != 'rb') { return false; } $this->position = 0; return true; } function stream_read ($length) { echo " reading {$length} at {$this->position}\n"; fseek(self::$stream, $this->position); $bytes = fread(self::$stream, $length); $this->position = $this->position + strlen($bytes); echo " read ", strlen($bytes), " bytes\n"; return $bytes; } function stream_tell () { echo " tell\n"; return $this->position; } function stream_eof () { echo " eof\n"; fseek(self::$stream, $this->position); return feof(self::$stream); } function stream_seek ($offset, $whence = SEEK_SET) { echo " seek from {$this->position} to {$offset}\n"; fseek(self::$stream, $this->position); $result = fseek(self::$stream, $offset, $whence); $this->position = ftell(self::$stream); echo " new position is {$this->position}\n"; return $result; } function stream_stat () { echo " stat\n"; 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'); echo "read 3 =\n", fread($stream, 3), "\n"; echo "tell =\n", ftell($stream), "\n"; echo "seek -1\n"; fseek($stream, -1, SEEK_CUR); echo "tell =\n", ftell($stream), "\n"; echo "read 2 =\n", fread($stream, 2), "\n"; echo "tell =\n", ftell($stream), "\n"; fclose($stream);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0oYBR
function name:  (null)
number of ops:  66
compiled vars:  !0 = $data, !1 = $stream_direct, !2 = $stream
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   INIT_FCALL                                               'stream_wrapper_register'
          1        SEND_VAL                                                 'request-file'
          2        SEND_VAL                                                 'File_stream'
          3        DO_ICALL                                                 
   58     4        ASSIGN                                                   !0, '0123456789abcdef'
   59     5        INIT_FCALL                                               'fopen'
          6        SEND_VAL                                                 'php%3A%2F%2Ftemp'
          7        SEND_VAL                                                 'w%2Bb'
          8        DO_ICALL                                         $5      
          9        ASSIGN                                                   !1, $5
   60    10        INIT_FCALL                                               'fwrite'
         11        SEND_VAR                                                 !1
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                                 
   61    14        INIT_FCALL                                               'rewind'
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                                 
   63    17        ASSIGN_STATIC_PROP                                       'stream', 'File_stream'
         18        OP_DATA                                                  !1
   65    19        INIT_FCALL                                               'fopen'
         20        SEND_VAL                                                 'request-file%3A%2F%2F'
         21        SEND_VAL                                                 'r'
         22        DO_ICALL                                         $10     
         23        ASSIGN                                                   !2, $10
   66    24        ECHO                                                     'read+3+%3D%0A'
         25        INIT_FCALL                                               'fread'
         26        SEND_VAR                                                 !2
         27        SEND_VAL                                                 3
         28        DO_ICALL                                         $12     
         29        ECHO                                                     $12
         30        ECHO                                                     '%0A'
   67    31        ECHO                                                     'tell+%3D%0A'
         32        INIT_FCALL                                               'ftell'
         33        SEND_VAR                                                 !2
         34        DO_ICALL                                         $13     
         35        ECHO                                                     $13
         36        ECHO                                                     '%0A'
   68    37        ECHO                                                     'seek+-1%0A'
         38        INIT_FCALL                                               'fseek'
         39        SEND_VAR                                                 !2
         40        SEND_VAL                                                 -1
         41        SEND_VAL                                                 1
         42        DO_ICALL                                                 
   69    43        ECHO                                                     'tell+%3D%0A'
         44        INIT_FCALL                                               'ftell'
         45        SEND_VAR                                                 !2
         46        DO_ICALL                                         $15     
         47        ECHO                                                     $15
         48        ECHO                                                     '%0A'
   70    49        ECHO                                                     'read+2+%3D%0A'
         50        INIT_FCALL                                               'fread'
         51        SEND_VAR                                                 !2
         52        SEND_VAL                                                 2
         53        DO_ICALL                                         $16     
         54        ECHO                                                     $16
         55        ECHO                                                     '%0A'
   71    56        ECHO                                                     'tell+%3D%0A'
         57        INIT_FCALL                                               'ftell'
         58        SEND_VAR                                                 !2
         59        DO_ICALL                                         $17     
         60        ECHO                                                     $17
         61        ECHO                                                     '%0A'
   72    62        INIT_FCALL                                               'fclose'
         63        SEND_VAR                                                 !2
         64        DO_ICALL                                                 
         65      > RETURN                                                   1

Class File_stream:
Function __get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0oYBR
function name:  __get
number of ops:  13
compiled vars:  !0 = $name, !1 = $n
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     1        CONCAT                                           ~2      '_', !0
          2        ASSIGN                                                   !1, ~2
    9     3        ROPE_INIT                                     5  ~6      '++get+'
          4        ROPE_ADD                                      1  ~6      ~6, !0
          5        ROPE_ADD                                      2  ~6      ~6, '+%3D+'
          6        FETCH_OBJ_R                                      ~4      !1
          7        ROPE_ADD                                      3  ~6      ~6, ~4
          8        ROPE_END                                      4  ~5      ~6, '%0A'
          9        ECHO                                                     ~5
   10    10        FETCH_OBJ_R                                      ~9      !1
         11      > RETURN                                                   ~9
   11    12*     > RETURN                                                   null

End of function __get

Function __set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0oYBR
function name:  __set
number of ops:  13
compiled vars:  !0 = $name, !1 = $value, !2 = $n
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   13     2        CONCAT                                           ~3      '_', !0
          3        ASSIGN                                                   !2, ~3
   14     4        ROPE_INIT                                     5  ~6      '++set+'
          5        ROPE_ADD                                      1  ~6      ~6, !0
          6        ROPE_ADD                                      2  ~6      ~6, '+%3D+'
          7        ROPE_ADD                                      3  ~6      ~6, !1
          8        ROPE_END                                      4  ~5      ~6, '%0A'
          9        ECHO                                                     ~5
   15    10        ASSIGN_OBJ                                               !2
         11        OP_DATA                                                  !1
   16    12      > RETURN                                                   null

End of function __set

Function stream_open:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/0oYBR
function name:  stream_open
number of ops:  13
compiled vars:  !0 = $path, !1 = $mode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   19     2        ECHO                                                     '++open%0A'
   20     3        IS_NOT_EQUAL                                     ~2      !1, 'r'
          4      > JMPZ_EX                                          ~2      ~2, ->7
          5    >   IS_NOT_EQUAL                                     ~3      !1, 'rb'
          6        BOOL                                             ~2      ~3
          7    > > JMPZ                                                     ~2, ->9
   21     8    > > RETURN                                                   <false>
   23     9    >   ASSIGN_OBJ                                               'position'
         10        OP_DATA                                                  0
   24    11      > RETURN                                                   <true>
   25    12*     > 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/0oYBR
function name:  stream_read
number of ops:  31
compiled vars:  !0 = $length, !1 = $bytes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   27     1        ROPE_INIT                                     5  ~4      '++reading+'
          2        ROPE_ADD                                      1  ~4      ~4, !0
          3        ROPE_ADD                                      2  ~4      ~4, '+at+'
          4        FETCH_OBJ_R                                      ~2      'position'
          5        ROPE_ADD                                      3  ~4      ~4, ~2
          6        ROPE_END                                      4  ~3      ~4, '%0A'
          7        ECHO                                                     ~3
   28     8        INIT_FCALL                                               'fseek'
          9        FETCH_STATIC_PROP_R          unknown             ~7      'stream'
         10        SEND_VAL                                                 ~7
         11        FETCH_OBJ_R                                      ~8      'position'
         12        SEND_VAL                                                 ~8
         13        DO_ICALL                                                 
   29    14        INIT_FCALL                                               'fread'
         15        FETCH_STATIC_PROP_R          unknown             ~10     'stream'
         16        SEND_VAL                                                 ~10
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                         $11     
         19        ASSIGN                                                   !1, $11
   30    20        FETCH_OBJ_R                                      ~14     'position'
         21        STRLEN                                           ~15     !1
         22        ADD                                              ~16     ~14, ~15
         23        ASSIGN_OBJ                                               'position'
         24        OP_DATA                                                  ~16
   31    25        ECHO                                                     '++read+'
         26        STRLEN                                           ~17     !1
         27        ECHO                                                     ~17
         28        ECHO                                                     '+bytes%0A'
   32    29      > RETURN                                                   !1
   33    30*     > 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/0oYBR
function name:  stream_tell
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   ECHO                                                     '+tell%0A'
   36     1        FETCH_OBJ_R                                      ~0      'position'
          2      > RETURN                                                   ~0
   37     3*     > 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/0oYBR
function name:  stream_eof
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   ECHO                                                     '++eof%0A'
   40     1        INIT_FCALL                                               'fseek'
          2        FETCH_STATIC_PROP_R          global lock         ~0      'stream'
          3        SEND_VAL                                                 ~0
          4        FETCH_OBJ_R                                      ~1      'position'
          5        SEND_VAL                                                 ~1
          6        DO_ICALL                                                 
   41     7        INIT_FCALL                                               'feof'
          8        FETCH_STATIC_PROP_R          unknown             ~3      'stream'
          9        SEND_VAL                                                 ~3
         10        DO_ICALL                                         $4      
         11      > RETURN                                                   $4
   42    12*     > 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/0oYBR
function name:  stream_seek
number of ops:  35
compiled vars:  !0 = $offset, !1 = $whence, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <const ast>
   44     2        ROPE_INIT                                     5  ~5      '++seek+from+'
          3        FETCH_OBJ_R                                      ~3      'position'
          4        ROPE_ADD                                      1  ~5      ~5, ~3
          5        ROPE_ADD                                      2  ~5      ~5, '+to+'
          6        ROPE_ADD                                      3  ~5      ~5, !0
          7        ROPE_END                                      4  ~4      ~5, '%0A'
          8        ECHO                                                     ~4
   45     9        INIT_FCALL                                               'fseek'
         10        FETCH_STATIC_PROP_R          unknown             ~8      'stream'
         11        SEND_VAL                                                 ~8
         12        FETCH_OBJ_R                                      ~9      'position'
         13        SEND_VAL                                                 ~9
         14        DO_ICALL                                                 
   46    15        INIT_FCALL                                               'fseek'
         16        FETCH_STATIC_PROP_R          unknown             ~11     'stream'
         17        SEND_VAL                                                 ~11
         18        SEND_VAR                                                 !0
         19        SEND_VAR                                                 !1
         20        DO_ICALL                                         $12     
         21        ASSIGN                                                   !2, $12
   47    22        INIT_FCALL                                               'ftell'
         23        FETCH_STATIC_PROP_R          unknown             ~15     'stream'
         24        SEND_VAL                                                 ~15
         25        DO_ICALL                                         $16     
         26        ASSIGN_OBJ                                               'position'
         27        OP_DATA                                                  $16
   48    28        ROPE_INIT                                     3  ~19     '++new+position+is+'
         29        FETCH_OBJ_R                                      ~17     'position'
         30        ROPE_ADD                                      1  ~19     ~19, ~17
         31        ROPE_END                                      2  ~18     ~19, '%0A'
         32        ECHO                                                     ~18
   49    33      > RETURN                                                   !2
   50    34*     > 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/0oYBR
function name:  stream_stat
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   ECHO                                                     '++stat%0A'
   53     1        INIT_FCALL                                               'fstat'
          2        FETCH_STATIC_PROP_R          global lock         ~0      'stream'
          3        SEND_VAL                                                 ~0
          4        DO_ICALL                                         $1      
          5      > RETURN                                                   $1
   54     6*     > RETURN                                                   null

End of function stream_stat

End of class File_stream.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
196.55 ms | 1412 KiB | 33 Q