3v4l.org

run code in 300+ PHP versions simultaneously
<?php class VariableStream { var $position; var $varname; function stream_open($path, $mode, $options, &$opened_path) { $url = parse_url($path); $this->varname = $url["host"]; $this->position = 0; return true; } function stream_read($count) { $ret = substr($GLOBALS[$this->varname], $this->position, $count); $this->position += strlen($ret); return $ret; } function stream_write($data) { $left = substr($GLOBALS[$this->varname], 0, $this->position); $right = substr($GLOBALS[$this->varname], $this->position + strlen($data)); $GLOBALS[$this->varname] = $left . $data . $right; $this->position += strlen($data); return strlen($data); } function stream_tell() { return $this->position; } function stream_eof() { return $this->position >= strlen($GLOBALS[$this->varname]); } function stream_seek($offset, $whence) { switch ($whence) { case SEEK_SET: if ($offset < strlen($GLOBALS[$this->varname]) && $offset >= 0) { $this->position = $offset; return true; } else { return false; } break; case SEEK_CUR: if ($offset >= 0) { $this->position += $offset; return true; } else { return false; } break; case SEEK_END: if (strlen($GLOBALS[$this->varname]) + $offset >= 0) { $this->position = strlen($GLOBALS[$this->varname]) + $offset; return true; } else { return false; } break; default: return false; } } function stream_metadata($path, $option, $var) { if($option == STREAM_META_TOUCH) { $url = parse_url($path); $varname = $url["host"]; if(!isset($GLOBALS[$varname])) { $GLOBALS[$varname] = ''; } return true; } return false; } } stream_wrapper_register("var", "VariableStream") or die("Failed to register protocol"); $myvar = ""; $fp = fopen("var://myvar", "r+"); fwrite($fp, "line1\n"); fwrite($fp, "line2\n"); fwrite($fp, "line3\n"); rewind($fp); while (!feof($fp)) { echo fgets($fp); } fclose($fp); var_dump($myvar);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 29
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 29
Branch analysis from position: 38
Branch analysis from position: 29
filename:       /in/5JuZt
function name:  (null)
number of ops:  45
compiled vars:  !0 = $myvar, !1 = $fp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   90     0  E >   INIT_FCALL                                               'stream_wrapper_register'
          1        SEND_VAL                                                 'var'
          2        SEND_VAL                                                 'VariableStream'
          3        DO_ICALL                                         $2      
          4      > JMPNZ_EX                                         ~3      $2, ->7
   91     5    > > EXIT                                                     'Failed+to+register+protocol'
          6*       BOOL                                             ~3      <true>
   93     7    >   ASSIGN                                                   !0, ''
   95     8        INIT_FCALL                                               'fopen'
          9        SEND_VAL                                                 'var%3A%2F%2Fmyvar'
         10        SEND_VAL                                                 'r%2B'
         11        DO_ICALL                                         $5      
         12        ASSIGN                                                   !1, $5
   97    13        INIT_FCALL                                               'fwrite'
         14        SEND_VAR                                                 !1
         15        SEND_VAL                                                 'line1%0A'
         16        DO_ICALL                                                 
   98    17        INIT_FCALL                                               'fwrite'
         18        SEND_VAR                                                 !1
         19        SEND_VAL                                                 'line2%0A'
         20        DO_ICALL                                                 
   99    21        INIT_FCALL                                               'fwrite'
         22        SEND_VAR                                                 !1
         23        SEND_VAL                                                 'line3%0A'
         24        DO_ICALL                                                 
  101    25        INIT_FCALL                                               'rewind'
         26        SEND_VAR                                                 !1
         27        DO_ICALL                                                 
  102    28      > JMP                                                      ->33
  103    29    >   INIT_FCALL                                               'fgets'
         30        SEND_VAR                                                 !1
         31        DO_ICALL                                         $11     
         32        ECHO                                                     $11
  102    33    >   INIT_FCALL                                               'feof'
         34        SEND_VAR                                                 !1
         35        DO_ICALL                                         $12     
         36        BOOL_NOT                                         ~13     $12
         37      > JMPNZ                                                    ~13, ->29
  105    38    >   INIT_FCALL                                               'fclose'
         39        SEND_VAR                                                 !1
         40        DO_ICALL                                                 
  106    41        INIT_FCALL                                               'var_dump'
         42        SEND_VAR                                                 !0
         43        DO_ICALL                                                 
         44      > RETURN                                                   1

Class VariableStream:
Function stream_open:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5JuZt
function name:  stream_open
number of ops:  15
compiled vars:  !0 = $path, !1 = $mode, !2 = $options, !3 = $opened_path, !4 = $url
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
    8     4        INIT_FCALL                                               'parse_url'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $5      
          7        ASSIGN                                                   !4, $5
    9     8        FETCH_DIM_R                                      ~8      !4, 'host'
          9        ASSIGN_OBJ                                               'varname'
         10        OP_DATA                                                  ~8
   10    11        ASSIGN_OBJ                                               'position'
         12        OP_DATA                                                  0
   12    13      > RETURN                                                   <true>
   13    14*     > 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/5JuZt
function name:  stream_read
number of ops:  16
compiled vars:  !0 = $count, !1 = $ret
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   17     1        INIT_FCALL                                               'substr'
          2        FETCH_OBJ_R                                      ~3      'varname'
          3        FETCH_R                      global              ~2      'GLOBALS'
          4        FETCH_DIM_R                                      ~4      ~2, ~3
          5        SEND_VAL                                                 ~4
          6        FETCH_OBJ_R                                      ~5      'position'
          7        SEND_VAL                                                 ~5
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $6      
         10        ASSIGN                                                   !1, $6
   18    11        STRLEN                                           ~9      !1
         12        ASSIGN_OBJ_OP                                 1          'position'
         13        OP_DATA                                                  ~9
   19    14      > RETURN                                                   !1
   20    15*     > RETURN                                                   null

End of function stream_read

Function stream_write:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5JuZt
function name:  stream_write
number of ops:  34
compiled vars:  !0 = $data, !1 = $left, !2 = $right
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   24     1        INIT_FCALL                                               'substr'
          2        FETCH_OBJ_R                                      ~4      'varname'
          3        FETCH_R                      global              ~3      'GLOBALS'
          4        FETCH_DIM_R                                      ~5      ~3, ~4
          5        SEND_VAL                                                 ~5
          6        SEND_VAL                                                 0
          7        FETCH_OBJ_R                                      ~6      'position'
          8        SEND_VAL                                                 ~6
          9        DO_ICALL                                         $7      
         10        ASSIGN                                                   !1, $7
   25    11        INIT_FCALL                                               'substr'
         12        FETCH_OBJ_R                                      ~10     'varname'
         13        FETCH_R                      global              ~9      'GLOBALS'
         14        FETCH_DIM_R                                      ~11     ~9, ~10
         15        SEND_VAL                                                 ~11
         16        FETCH_OBJ_R                                      ~12     'position'
         17        STRLEN                                           ~13     !0
         18        ADD                                              ~14     ~12, ~13
         19        SEND_VAL                                                 ~14
         20        DO_ICALL                                         $15     
         21        ASSIGN                                                   !2, $15
   26    22        FETCH_OBJ_R                                      ~18     'varname'
         23        CONCAT                                           ~20     !1, !0
         24        CONCAT                                           ~21     ~20, !2
         25        FETCH_W                      global              $17     'GLOBALS'
         26        ASSIGN_DIM                                               $17, ~18
         27        OP_DATA                                                  ~21
   27    28        STRLEN                                           ~23     !0
         29        ASSIGN_OBJ_OP                                 1          'position'
         30        OP_DATA                                                  ~23
   28    31        STRLEN                                           ~24     !0
         32      > RETURN                                                   ~24
   29    33*     > RETURN                                                   null

End of function stream_write

Function stream_tell:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5JuZt
function name:  stream_tell
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   FETCH_OBJ_R                                      ~0      'position'
          1      > RETURN                                                   ~0
   34     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/5JuZt
function name:  stream_eof
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   FETCH_OBJ_R                                      ~0      'position'
          1        FETCH_OBJ_R                                      ~2      'varname'
          2        FETCH_R                      global              ~1      'GLOBALS'
          3        FETCH_DIM_R                                      ~3      ~1, ~2
          4        STRLEN                                           ~4      ~3
          5        IS_SMALLER_OR_EQUAL                              ~5      ~4, ~0
          6      > RETURN                                                   ~5
   39     7*     > RETURN                                                   null

End of function stream_eof

Function stream_seek:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 6, Position 2 = 24
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 32
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 48
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 30
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 46) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 22
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/5JuZt
function name:  stream_seek
number of ops:  52
compiled vars:  !0 = $offset, !1 = $whence
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   43     2        IS_EQUAL                                                 !1, 0
          3      > JMPNZ                                                    ~2, ->9
          4    >   IS_EQUAL                                                 !1, 1
          5      > JMPNZ                                                    ~2, ->24
          6    >   IS_EQUAL                                                 !1, 2
          7      > JMPNZ                                                    ~2, ->32
          8    > > JMP                                                      ->50
   45     9    >   FETCH_OBJ_R                                      ~4      'varname'
         10        FETCH_R                      global              ~3      'GLOBALS'
         11        FETCH_DIM_R                                      ~5      ~3, ~4
         12        STRLEN                                           ~6      ~5
         13        IS_SMALLER                                       ~7      !0, ~6
         14      > JMPZ_EX                                          ~7      ~7, ->17
         15    >   IS_SMALLER_OR_EQUAL                              ~8      0, !0
         16        BOOL                                             ~7      ~8
         17    > > JMPZ                                                     ~7, ->22
   46    18    >   ASSIGN_OBJ                                               'position'
         19        OP_DATA                                                  !0
   47    20      > RETURN                                                   <true>
         21*       JMP                                                      ->23
   49    22    > > RETURN                                                   <false>
   51    23*       JMP                                                      ->51
   54    24    >   IS_SMALLER_OR_EQUAL                                      0, !0
         25      > JMPZ                                                     ~10, ->30
   55    26    >   ASSIGN_OBJ_OP                                 1          'position'
         27        OP_DATA                                                  !0
   56    28      > RETURN                                                   <true>
         29*       JMP                                                      ->31
   58    30    > > RETURN                                                   <false>
   60    31*       JMP                                                      ->51
   63    32    >   FETCH_OBJ_R                                      ~13     'varname'
         33        FETCH_R                      global              ~12     'GLOBALS'
         34        FETCH_DIM_R                                      ~14     ~12, ~13
         35        STRLEN                                           ~15     ~14
         36        ADD                                              ~16     ~15, !0
         37        IS_SMALLER_OR_EQUAL                                      0, ~16
         38      > JMPZ                                                     ~17, ->48
   64    39    >   FETCH_OBJ_R                                      ~20     'varname'
         40        FETCH_R                      global              ~19     'GLOBALS'
         41        FETCH_DIM_R                                      ~21     ~19, ~20
         42        STRLEN                                           ~22     ~21
         43        ADD                                              ~23     ~22, !0
         44        ASSIGN_OBJ                                               'position'
         45        OP_DATA                                                  ~23
   65    46      > RETURN                                                   <true>
         47*       JMP                                                      ->49
   67    48    > > RETURN                                                   <false>
   69    49*       JMP                                                      ->51
   72    50    > > RETURN                                                   <false>
   74    51*     > RETURN                                                   null

End of function stream_seek

Function stream_metadata:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 19
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 18
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5JuZt
function name:  stream_metadata
number of ops:  21
compiled vars:  !0 = $path, !1 = $option, !2 = $var, !3 = $url, !4 = $varname
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   76     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   78     3        IS_EQUAL                                                 !1, 1
          4      > JMPZ                                                     ~5, ->19
   79     5    >   INIT_FCALL                                               'parse_url'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $6      
          8        ASSIGN                                                   !3, $6
   80     9        FETCH_DIM_R                                      ~8      !3, 'host'
         10        ASSIGN                                                   !4, ~8
   81    11        FETCH_IS                                         ~10     'GLOBALS'
         12        ISSET_ISEMPTY_DIM_OBJ                         0  ~11     ~10, !4
         13        BOOL_NOT                                         ~12     ~11
         14      > JMPZ                                                     ~12, ->18
   82    15    >   FETCH_W                      global              $13     'GLOBALS'
         16        ASSIGN_DIM                                               $13, !4
         17        OP_DATA                                                  ''
   84    18    > > RETURN                                                   <true>
   86    19    > > RETURN                                                   <false>
   87    20*     > RETURN                                                   null

End of function stream_metadata

End of class VariableStream.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.51 ms | 1420 KiB | 33 Q