[php-src] Issue #19091: exec() removes trailing newline

From: Date: Thu, 10 Jul 2025 22:15:48 +0000
Subject: [php-src] Issue #19091: exec() removes trailing newline
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-250414@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/19091 Author: kkmuffme ### Description The following code: ```php <?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 ```plain PHP 8.4 ``` ### Operating System _No response_

« previous php.bugs (#250414) next »