wp-cli / php-cli-tools

A collection of tools to help with PHP command line utilities
MIT License
671 stars 117 forks source link

Streams::input broken with PHP7.4 #140

Closed nono303 closed 4 years ago

nono303 commented 4 years ago

Hi,

I actually test PHP7.4 (Win64 NTS) and I find a break on Stream::input

Stack Trace

Error   Uncaught Exception: Caught ^D during input in \php-cli-tools\lib\cli\Streams.php:141
#0 \php-cli-tools\lib\cli\Streams.php(234): cli\Streams::input()
#1 \php-cli-tools\lib\cli\cli.php(152): cli\Streams::menu(Array, NULL, '?')
#2 \phpsh\menu.php(45): cli\menu(Array, NULL, '?')
#3 {main} thrown in \php-cli-tools\lib\cli\Streams.php(141)

Workaround using readlinein \php-cli-toolslib\cli\Streams.php with this patch:

129c129
<       if( $format ) {
---
      /*if( $format ) {
133a134,135
      */
      $line = readline();
139d140
< 

Actually, I don't understand why fscanf & fgets on STDIN return falsewith PHP7.4 (didn't read any change on it) bug the workaround didn't take into account $format. However, a quick look on input function usage doesn't show any call (on cli.php or stream.php) with $format specified

\php-cli-tools\lib\cli\cli.php"(89,16): return Streams::input( $format ); // unused??
\php-cli-tools\lib\cli\Streams.php"(167,16):            $line = self::input( null, $hide );
\php-cli-tools\lib\cli\Streams.php"(235,16):            $line = self::input();

So, If you have any explanation, idea or other, thanks for your feedback!

nono303 commented 4 years ago

resolved with php7.4.4