3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class sf extends php_user_filter { function onCreate() { //var_dump($this); } function filter($in, $out, &$consumed, $closing) { //var_dump(func_get_args()); if(!$closing) { $bucket = stream_bucket_make_writeable($in); $bucket->data = 'A'.$bucket->data.'B'; $consumed += $bucket->datalen; stream_bucket_prepend($out, $bucket); return PSFS_PASS_ON; } else { return PSFS_FEED_ME; } } } $r = fopen('php://memory', 'wb+'); stream_filter_register('sf', 'sf' ); stream_filter_append($r, 'sf', STREAM_FILTER_READ); fwrite($r, 'lol'); rewind($r); var_dump(fread($r, 1)); echo fread($r, 2);
based on k3HWj
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.3.0alpha1
string(1) "A" lo