3v4l.org

run code in 300+ PHP versions simultaneously
<?php fclose(STDIN); fclose(STDOUT); fclose(STDERR); $STDIN = fopen('/dev/null', 'r'); $STDOUT = fopen('php://output', 'wb'); $STDERR = fopen('/dev/null', 'wb'); class TestFilterClass { function filter($in, $out) { while (true) { $bucket = stream_bucket_make_writeable($in); if (is_object($bucket)) { $bucket->data = sprintf('[%s] %s', __METHOD__, $bucket->data); stream_bucket_append($out, $bucket); } break; } return PSFS_PASS_ON; } } if (stream_filter_register('TestFilter', 'TestFilterClass')) { $handle = stream_filter_append(STDOUT, 'TestFilter'); if (is_resource($handle)) { fwrite(STDOUT, 'hello world' . PHP_EOL); // ok echo 'hello world' . PHP_EOL; // nope stream_filter_remove($handle); } }
Output for 7.3.0 - 7.3.31, 7.4.0 - 7.4.25, 7.4.27 - 7.4.32, 8.0.0 - 8.0.19, 8.0.21 - 8.0.30, 8.1.0 - 8.1.6, 8.1.9 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6

Process exited with code 255.
Output for 8.0.20, 8.1.7 - 8.1.8
Warning: fopen(): open_basedir restriction in effect. File(/dev/null) is not within the allowed path(s): (/tmp:/in:/etc) in /in/cJBA2 on line 6 Warning: fopen(/dev/null): Failed to open stream: Operation not permitted in /in/cJBA2 on line 6 Warning: fopen(): open_basedir restriction in effect. File(/dev/null) is not within the allowed path(s): (/tmp:/in:/etc) in /in/cJBA2 on line 8 Warning: fopen(/dev/null): Failed to open stream: Operation not permitted in /in/cJBA2 on line 8 Fatal error: Uncaught TypeError: stream_filter_append(): supplied resource is not a valid stream resource in /in/cJBA2:32 Stack trace: #0 /in/cJBA2(32): stream_filter_append(Resource id #2, 'TestFilter') #1 {main} thrown in /in/cJBA2 on line 32
Process exited with code 255.
Output for 5.2.3 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.35, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.32 - 7.3.33, 7.4.26, 7.4.33
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.2
Notice: Use of undefined constant STDIN - assumed 'STDIN' in /in/cJBA2 on line 3 Warning: fclose(): supplied argument is not a valid stream resource in /in/cJBA2 on line 3 Notice: Use of undefined constant STDOUT - assumed 'STDOUT' in /in/cJBA2 on line 4 Warning: fclose(): supplied argument is not a valid stream resource in /in/cJBA2 on line 4 Notice: Use of undefined constant STDERR - assumed 'STDERR' in /in/cJBA2 on line 5 Warning: fclose(): supplied argument is not a valid stream resource in /in/cJBA2 on line 5 Notice: Use of undefined constant STDOUT - assumed 'STDOUT' in /in/cJBA2 on line 32 Warning: stream_filter_append() expects parameter 1 to be resource, string given in /in/cJBA2 on line 32
Output for 4.4.5 - 4.4.9
Notice: Use of undefined constant STDIN - assumed 'STDIN' in /in/cJBA2 on line 3 Warning: fclose(): supplied argument is not a valid stream resource in /in/cJBA2 on line 3 Notice: Use of undefined constant STDOUT - assumed 'STDOUT' in /in/cJBA2 on line 4 Warning: fclose(): supplied argument is not a valid stream resource in /in/cJBA2 on line 4 Notice: Use of undefined constant STDERR - assumed 'STDERR' in /in/cJBA2 on line 5 Warning: fclose(): supplied argument is not a valid stream resource in /in/cJBA2 on line 5 Fatal error: Call to undefined function: stream_filter_register() in /in/cJBA2 on line 30
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.4
Notice: Use of undefined constant STDIN - assumed 'STDIN' in /in/cJBA2 on line 3 Warning: fclose(): supplied argument is not a valid stream resource in /in/cJBA2 on line 3 Notice: Use of undefined constant STDOUT - assumed 'STDOUT' in /in/cJBA2 on line 4 Warning: fclose(): supplied argument is not a valid stream resource in /in/cJBA2 on line 4 Notice: Use of undefined constant STDERR - assumed 'STDERR' in /in/cJBA2 on line 5 Warning: fclose(): supplied argument is not a valid stream resource in /in/cJBA2 on line 5 Fatal error: Call to undefined function: stream_filter_register() in /in/cJBA2 on line 30
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Notice: Use of undefined constant STDIN - assumed 'STDIN' in /in/cJBA2 on line 3 Warning: fclose(): supplied argument is not a valid stream resource in /in/cJBA2 on line 3 Notice: Use of undefined constant STDOUT - assumed 'STDOUT' in /in/cJBA2 on line 4 Warning: fclose(): supplied argument is not a valid stream resource in /in/cJBA2 on line 4 Notice: Use of undefined constant STDERR - assumed 'STDERR' in /in/cJBA2 on line 5 Warning: fclose(): supplied argument is not a valid stream resource in /in/cJBA2 on line 5 Fatal error: Call to undefined function: stream_filter_register() in /in/cJBA2 on line 30

preferences:
249.07 ms | 402 KiB | 375 Q