3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo 'bug'; // Should be transformed by filter on second include if (!class_exists(SampleFilter::class)) { class SampleFilter extends php_user_filter { private $data = ''; public function filter($in, $out, &$consumed, $closing) { while ($bucket = stream_bucket_make_writeable($in)) { $this->data .= $bucket->data; } if ($closing || feof($this->stream)) { $consumed = strlen($this->data); $this->data = str_replace('bug', 'feature', $this->data); $bucket = stream_bucket_new($this->stream, $this->data); stream_bucket_append($out, $bucket); return PSFS_PASS_ON; } return PSFS_FEED_ME; } } stream_filter_register('sample.filter', SampleFilter::class); $uri = 'php://filter/read=sample.filter/resource='. __FILE__; $content = file_get_contents($uri); echo '<pre>', htmlentities($content), '</pre>'; // Looks good include $uri; // We expect one more "feature" output at line 3 }
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.28, 7.4.0 - 7.4.14, 8.0.0 - 8.0.3
bug<pre>&lt;?php echo 'feature'; // Should be transformed by filter on second include if (!class_exists(SampleFilter::class)) { class SampleFilter extends php_user_filter { private $data = ''; public function filter($in, $out, &amp;$consumed, $closing) { while ($bucket = stream_bucket_make_writeable($in)) { $this-&gt;data .= $bucket-&gt;data; } if ($closing || feof($this-&gt;stream)) { $consumed = strlen($this-&gt;data); $this-&gt;data = str_replace('feature', 'feature', $this-&gt;data); $bucket = stream_bucket_new($this-&gt;stream, $this-&gt;data); stream_bucket_append($out, $bucket); return PSFS_PASS_ON; } return PSFS_FEED_ME; } } stream_filter_register('sample.filter', SampleFilter::class); $uri = 'php://filter/read=sample.filter/resource='. __FILE__; $content = file_get_contents($uri); echo '&lt;pre&gt;', htmlentities($content), '&lt;/pre&gt;'; // Looks good include $uri; // We expect one more &quot;feature&quot; output at line 3 }</pre>feature