3v4l.org

run code in 300+ PHP versions simultaneously
<?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'; //var_dump($bucket, $closing); /*while ($bucket = stream_bucket_make_writeable($in)) { */ $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, 1024)); //echo fread($r, 2);
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Deprecated: Return type of sf::filter($in, $out, &$consumed, $closing) should either be compatible with php_user_filter::filter($in, $out, &$consumed, bool $closing): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/k3HWj on line 8 Deprecated: Return type of sf::onCreate() should either be compatible with php_user_filter::onCreate(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/k3HWj on line 5 array(4) { [0]=> resource(7) of type (userfilter.bucket brigade) [1]=> resource(8) of type (userfilter.bucket brigade) [2]=> NULL [3]=> bool(false) } array(4) { [0]=> resource(10) of type (userfilter.bucket brigade) [1]=> resource(11) of type (userfilter.bucket brigade) [2]=> NULL [3]=> bool(true) } string(5) "AlolB"
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Deprecated: Return type of sf::filter($in, $out, &$consumed, $closing) should either be compatible with php_user_filter::filter($in, $out, &$consumed, bool $closing): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/k3HWj on line 8 Deprecated: Return type of sf::onCreate() should either be compatible with php_user_filter::onCreate(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/k3HWj on line 5 array(4) { [0]=> resource(7) of type (userfilter.bucket brigade) [1]=> resource(8) of type (userfilter.bucket brigade) [2]=> NULL [3]=> bool(false) } array(4) { [0]=> resource(10) of type (userfilter.bucket brigade) [1]=> resource(11) of type (userfilter.bucket brigade) [2]=> NULL [3]=> bool(true) } string(5) "AlolB"
Output for 5.6.38, 7.0.0 - 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
array(4) { [0]=> resource(8) of type (userfilter.bucket brigade) [1]=> resource(9) of type (userfilter.bucket brigade) [2]=> NULL [3]=> bool(false) } array(4) { [0]=> resource(11) of type (userfilter.bucket brigade) [1]=> resource(12) of type (userfilter.bucket brigade) [2]=> NULL [3]=> bool(true) } string(5) "AlolB"

preferences:
186.78 ms | 403 KiB | 216 Q