3v4l.org

run code in 300+ PHP versions simultaneously
<?php class StringStreamWrapper { const PROTOCOL = "stringstream"; private $stringstream; private $position; private $stringlength; public function stream_open($path, $mode, $options, &$opened_path) { $contextOptions = stream_context_get_options($this->context); if (!isset($contextOptions[self::PROTOCOL]['string'])) return false; $this->position = 0; // this is our stream! $this->stringstream = $contextOptions[self::PROTOCOL]['string']; $this->stringlength = strlen($this->stringstream); return true; } public function stream_read($len) { $data = substr($this->stringstream, $this->position, $len); $this->position += strlen($data); return $data; } public function stream_write($data){ $l = strlen($data); $this->stringstream = substr($this->stringstream, 0, $this->position) . $data . substr($this->stringstream, $this->position += $l); $this->stringlength = strlen($this->stringstream); return $l; } public function stream_seek($offset, $whence = SEEK_SET) { if ($whence == SEEK_CUR) { $this->position += $offset; } else if ($whence == SEEK_END) { $this->position = $this->stringlength + $offset; } else { $this->position = $offset; } return true; } public function stream_tell() { return $this->position; } public function stream_eof() { return ($this->position >= $this->stringlength); } public function stream_stat() { return array( 7 => $this->stringlength, 'size' => $this->stringlength, ); } static public function Open($string) { $context = stream_context_create(array(self::PROTOCOL => array('string' => &$string))); return fopen(self::PROTOCOL . "://",'r', false, $context); } } stream_wrapper_register(StringStreamWrapper::PROTOCOL, "StringStreamWrapper"); class replace_nullchar_filter extends php_user_filter { function filter($in, $out, &$consumed, $closing) { while ($bucket = stream_bucket_make_writeable($in)) { $bucket->data = str_replace("\0", "", $bucket->data); $consumed += $bucket->datalen; stream_bucket_append($out, $bucket); } return PSFS_PASS_ON; } } stream_filter_register('replacenullchar', 'replace_nullchar_filter'); class StringStreamWrapperFixed { public static function bug68532fixed() { if (defined('BUG68532FIXED')) return BUG68532FIXED; return version_compare(PHP_VERSION, '5.6.5', '>=') || (version_compare(PHP_VERSION, '5.5.21', '>=') && version_compare(PHP_VERSION, '5.6.0', '<')); } public static function Open($string) { if (self::bug68532fixed()) { $stream = fopen('php://temp', 'r+'); } else { $stream = tmpfile(); } fwrite($stream, $string); rewind($stream); return $stream; } } ####################################### $testString = 'test'; echo "base64_encode = " . base64_encode($testString).PHP_EOL; ####################################### # put some data in the StringStreamWrapper $stringstream = StringStreamWrapper::Open($testString); # emulate the output stream (in memory) $output = fopen('php://memory','r+'); # attach write filter to output $filter = stream_filter_append($output, 'convert.base64-encode'); flush($output); # write to output $written = stream_copy_to_stream($stringstream, $output); # remove filter stream_filter_remove($filter); rewind($output); echo "from outputstream = " . stream_get_contents($output).PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/23jMT
function name:  (null)
number of ops:  50
compiled vars:  !0 = $testString, !1 = $stringstream, !2 = $output, !3 = $filter, !4 = $written
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   71     0  E >   INIT_FCALL                                               'stream_wrapper_register'
          1        SEND_VAL                                                 'stringstream'
          2        SEND_VAL                                                 'StringStreamWrapper'
          3        DO_ICALL                                                 
   83     4        INIT_FCALL                                               'stream_filter_register'
          5        SEND_VAL                                                 'replacenullchar'
          6        SEND_VAL                                                 'replace_nullchar_filter'
          7        DO_ICALL                                                 
  107     8        ASSIGN                                                   !0, 'test'
  109     9        INIT_FCALL                                               'base64_encode'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $8      
         12        CONCAT                                           ~9      'base64_encode+%3D+', $8
         13        CONCAT                                           ~10     ~9, '%0A'
         14        ECHO                                                     ~10
  114    15        INIT_STATIC_METHOD_CALL                                  'StringStreamWrapper', 'Open'
         16        SEND_VAR                                                 !0
         17        DO_FCALL                                      0  $11     
         18        ASSIGN                                                   !1, $11
  117    19        INIT_FCALL                                               'fopen'
         20        SEND_VAL                                                 'php%3A%2F%2Fmemory'
         21        SEND_VAL                                                 'r%2B'
         22        DO_ICALL                                         $13     
         23        ASSIGN                                                   !2, $13
  120    24        INIT_FCALL                                               'stream_filter_append'
         25        SEND_VAR                                                 !2
         26        SEND_VAL                                                 'convert.base64-encode'
         27        DO_ICALL                                         $15     
         28        ASSIGN                                                   !3, $15
  122    29        INIT_FCALL                                               'flush'
         30        SEND_VAR                                                 !2
         31        DO_ICALL                                                 
  124    32        INIT_FCALL                                               'stream_copy_to_stream'
         33        SEND_VAR                                                 !1
         34        SEND_VAR                                                 !2
         35        DO_ICALL                                         $18     
         36        ASSIGN                                                   !4, $18
  127    37        INIT_FCALL                                               'stream_filter_remove'
         38        SEND_VAR                                                 !3
         39        DO_ICALL                                                 
  129    40        INIT_FCALL                                               'rewind'
         41        SEND_VAR                                                 !2
         42        DO_ICALL                                                 
  130    43        INIT_FCALL                                               'stream_get_contents'
         44        SEND_VAR                                                 !2
         45        DO_ICALL                                         $22     
         46        CONCAT                                           ~23     'from+outputstream+%3D+', $22
         47        CONCAT                                           ~24     ~23, '%0A'
         48        ECHO                                                     ~24
         49      > RETURN                                                   1

Class StringStreamWrapper:
Function stream_open:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 14
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/23jMT
function name:  stream_open
number of ops:  26
compiled vars:  !0 = $path, !1 = $mode, !2 = $options, !3 = $opened_path, !4 = $contextOptions
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   11     4        INIT_FCALL                                               'stream_context_get_options'
          5        FETCH_OBJ_R                                      ~5      'context'
          6        SEND_VAL                                                 ~5
          7        DO_ICALL                                         $6      
          8        ASSIGN                                                   !4, $6
   12     9        FETCH_DIM_IS                                     ~8      !4, 'stringstream'
         10        ISSET_ISEMPTY_DIM_OBJ                         0  ~9      ~8, 'string'
         11        BOOL_NOT                                         ~10     ~9
         12      > JMPZ                                                     ~10, ->14
   13    13    > > RETURN                                                   <false>
   15    14    >   ASSIGN_OBJ                                               'position'
         15        OP_DATA                                                  0
   18    16        FETCH_DIM_R                                      ~13     !4, 'stringstream'
         17        FETCH_DIM_R                                      ~14     ~13, 'string'
         18        ASSIGN_OBJ                                               'stringstream'
         19        OP_DATA                                                  ~14
   20    20        FETCH_OBJ_R                                      ~16     'stringstream'
         21        STRLEN                                           ~17     ~16
         22        ASSIGN_OBJ                                               'stringlength'
         23        OP_DATA                                                  ~17
   22    24      > RETURN                                                   <true>
   23    25*     > 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/23jMT
function name:  stream_read
number of ops:  14
compiled vars:  !0 = $len, !1 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   26     1        INIT_FCALL                                               'substr'
          2        FETCH_OBJ_R                                      ~2      'stringstream'
          3        SEND_VAL                                                 ~2
          4        FETCH_OBJ_R                                      ~3      'position'
          5        SEND_VAL                                                 ~3
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $4      
          8        ASSIGN                                                   !1, $4
   27     9        STRLEN                                           ~7      !1
         10        ASSIGN_OBJ_OP                                 1          'position'
         11        OP_DATA                                                  ~7
   28    12      > RETURN                                                   !1
   29    13*     > 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/23jMT
function name:  stream_write
number of ops:  27
compiled vars:  !0 = $data, !1 = $l
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   32     1        STRLEN                                           ~2      !0
          2        ASSIGN                                                   !1, ~2
   33     3        INIT_FCALL                                               'substr'
          4        FETCH_OBJ_R                                      ~5      'stringstream'
          5        SEND_VAL                                                 ~5
          6        SEND_VAL                                                 0
          7        FETCH_OBJ_R                                      ~6      'position'
          8        SEND_VAL                                                 ~6
          9        DO_ICALL                                         $7      
         10        CONCAT                                           ~8      $7, !0
         11        INIT_FCALL                                               'substr'
         12        FETCH_OBJ_R                                      ~9      'stringstream'
         13        SEND_VAL                                                 ~9
         14        ASSIGN_OBJ_OP                                 1  ~10     'position'
         15        OP_DATA                                                  !1
         16        SEND_VAL                                                 ~10
         17        DO_ICALL                                         $11     
         18        CONCAT                                           ~12     ~8, $11
         19        ASSIGN_OBJ                                               'stringstream'
         20        OP_DATA                                                  ~12
   34    21        FETCH_OBJ_R                                      ~14     'stringstream'
         22        STRLEN                                           ~15     ~14
         23        ASSIGN_OBJ                                               'stringlength'
         24        OP_DATA                                                  ~15
   35    25      > RETURN                                                   !1
   36    26*     > RETURN                                                   null

End of function stream_write

Function stream_seek:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/23jMT
function name:  stream_seek
number of ops:  18
compiled vars:  !0 = $offset, !1 = $whence
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <const ast>
   39     2        IS_EQUAL                                                 !1, 1
          3      > JMPZ                                                     ~2, ->7
   40     4    >   ASSIGN_OBJ_OP                                 1          'position'
          5        OP_DATA                                                  !0
          6      > JMP                                                      ->16
   42     7    >   IS_EQUAL                                                 !1, 2
          8      > JMPZ                                                     ~4, ->14
   43     9    >   FETCH_OBJ_R                                      ~6      'stringlength'
         10        ADD                                              ~7      ~6, !0
         11        ASSIGN_OBJ                                               'position'
         12        OP_DATA                                                  ~7
         13      > JMP                                                      ->16
   46    14    >   ASSIGN_OBJ                                               'position'
         15        OP_DATA                                                  !0
   48    16    > > RETURN                                                   <true>
   49    17*     > RETURN                                                   null

End of function stream_seek

Function stream_tell:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/23jMT
function name:  stream_tell
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   FETCH_OBJ_R                                      ~0      'position'
          1      > RETURN                                                   ~0
   53     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/23jMT
function name:  stream_eof
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   FETCH_OBJ_R                                      ~0      'position'
          1        FETCH_OBJ_R                                      ~1      'stringlength'
          2        IS_SMALLER_OR_EQUAL                              ~2      ~1, ~0
          3      > RETURN                                                   ~2
   57     4*     > RETURN                                                   null

End of function stream_eof

Function stream_stat:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/23jMT
function name:  stream_stat
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   FETCH_OBJ_R                                      ~0      'stringlength'
          1        INIT_ARRAY                                       ~1      ~0, 7
   62     2        FETCH_OBJ_R                                      ~2      'stringlength'
          3        ADD_ARRAY_ELEMENT                                ~1      ~2, 'size'
          4      > RETURN                                                   ~1
   64     5*     > RETURN                                                   null

End of function stream_stat

Function open:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/23jMT
function name:  Open
number of ops:  15
compiled vars:  !0 = $string, !1 = $context
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   RECV                                             !0      
   67     1        INIT_FCALL                                               'stream_context_create'
          2        INIT_ARRAY                                       ~2      !0, 'string'
          3        INIT_ARRAY                                       ~3      ~2, 'stringstream'
          4        SEND_VAL                                                 ~3
          5        DO_ICALL                                         $4      
          6        ASSIGN                                                   !1, $4
   68     7        INIT_FCALL                                               'fopen'
          8        SEND_VAL                                                 'stringstream%3A%2F%2F'
          9        SEND_VAL                                                 'r'
         10        SEND_VAL                                                 <false>
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                         $6      
         13      > RETURN                                                   $6
   69    14*     > RETURN                                                   null

End of function open

End of class StringStreamWrapper.

Class replace_nullchar_filter:
Function filter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 5
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 5
Branch analysis from position: 24
Branch analysis from position: 5
filename:       /in/23jMT
function name:  filter
number of ops:  26
compiled vars:  !0 = $in, !1 = $out, !2 = $consumed, !3 = $closing, !4 = $bucket
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   74     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   75     4      > JMP                                                      ->19
   76     5    >   INIT_FCALL                                               'str_replace'
          6        SEND_VAL                                                 '%00'
          7        SEND_VAL                                                 ''
          8        FETCH_OBJ_R                                      ~6      !4, 'data'
          9        SEND_VAL                                                 ~6
         10        DO_ICALL                                         $7      
         11        ASSIGN_OBJ                                               !4, 'data'
         12        OP_DATA                                                  $7
   77    13        FETCH_OBJ_R                                      ~8      !4, 'datalen'
         14        ASSIGN_OP                                     1          !2, ~8
   78    15        INIT_FCALL                                               'stream_bucket_append'
         16        SEND_VAR                                                 !1
         17        SEND_VAR                                                 !4
         18        DO_ICALL                                                 
   75    19    >   INIT_FCALL                                               'stream_bucket_make_writeable'
         20        SEND_VAR                                                 !0
         21        DO_ICALL                                         $11     
         22        ASSIGN                                           ~12     !4, $11
         23      > JMPNZ                                                    ~12, ->5
   80    24    > > RETURN                                                   2
   81    25*     > RETURN                                                   null

End of function filter

End of class replace_nullchar_filter.

Class StringStreamWrapperFixed:
Function bug68532fixed:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 2, Position 2 = 4
Branch analysis from position: 2
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 47) Position 1 = 10, Position 2 = 23
Branch analysis from position: 10
2 jumps found. (Code = 46) Position 1 = 16, Position 2 = 22
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
Branch analysis from position: 23
filename:       /in/23jMT
function name:  bug68532fixed
number of ops:  25
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   88     0  E >   DEFINED                                                  'BUG68532FIXED'
          1      > JMPZ                                                     ~0, ->4
   89     2    >   FETCH_CONSTANT                                   ~1      'BUG68532FIXED'
          3      > RETURN                                                   ~1
   90     4    >   INIT_FCALL                                               'version_compare'
          5        SEND_VAL                                                 '8.0.0'
          6        SEND_VAL                                                 '5.6.5'
          7        SEND_VAL                                                 '%3E%3D'
          8        DO_ICALL                                         $2      
          9      > JMPNZ_EX                                         ~3      $2, ->23
   91    10    >   INIT_FCALL                                               'version_compare'
         11        SEND_VAL                                                 '8.0.0'
         12        SEND_VAL                                                 '5.5.21'
         13        SEND_VAL                                                 '%3E%3D'
         14        DO_ICALL                                         $4      
         15      > JMPZ_EX                                          ~5      $4, ->22
         16    >   INIT_FCALL                                               'version_compare'
         17        SEND_VAL                                                 '8.0.0'
         18        SEND_VAL                                                 '5.6.0'
         19        SEND_VAL                                                 '%3C'
         20        DO_ICALL                                         $6      
         21        BOOL                                             ~5      $6
         22    >   BOOL                                             ~3      ~5
         23    > > RETURN                                                   ~3
   92    24*     > RETURN                                                   null

End of function bug68532fixed

Function open:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/23jMT
function name:  Open
number of ops:  22
compiled vars:  !0 = $string, !1 = $stream
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   94     0  E >   RECV                                             !0      
   95     1        INIT_STATIC_METHOD_CALL                                  'bug68532fixed'
          2        DO_FCALL                                      0  $2      
          3      > JMPZ                                                     $2, ->10
   96     4    >   INIT_FCALL                                               'fopen'
          5        SEND_VAL                                                 'php%3A%2F%2Ftemp'
          6        SEND_VAL                                                 'r%2B'
          7        DO_ICALL                                         $3      
          8        ASSIGN                                                   !1, $3
          9      > JMP                                                      ->13
   98    10    >   INIT_FCALL                                               'tmpfile'
         11        DO_ICALL                                         $5      
         12        ASSIGN                                                   !1, $5
  100    13    >   INIT_FCALL                                               'fwrite'
         14        SEND_VAR                                                 !1
         15        SEND_VAR                                                 !0
         16        DO_ICALL                                                 
  101    17        INIT_FCALL                                               'rewind'
         18        SEND_VAR                                                 !1
         19        DO_ICALL                                                 
  102    20      > RETURN                                                   !1
  103    21*     > RETURN                                                   null

End of function open

End of class StringStreamWrapperFixed.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
186.8 ms | 1420 KiB | 51 Q