Open
Description
Description
The following code:
<?php
echo substr_count( shell_exec( 'echo "hello"; echo "world"' ), PHP_EOL ) . PHP_EOL;
exec( 'echo "hello"; echo "world"', $output );
echo substr_count( implode( PHP_EOL, $output ), PHP_EOL ) . PHP_EOL;
Resulted in this output:
2
1
But I expected this output instead:
2
2
This makes it impossible to know whether the output contained a trailing newline or not in "exec()", however this can be significant. (using shell_exec with explode isn't an alternative, since I generally also need the exit code)
Changing this will probably break tons of code, therefore I guess this should be handled with an additional param perhaps? ($output_exclude_last_trailing_newline = false)
PHP Version
PHP 8.4
Operating System
No response