wp-cli / php-cli-tools

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

PHP 8.2 deprecation: ASCII renderer with empty row values. #159

Closed Soean closed 1 year ago

Soean commented 1 year ago

Bug Report

Describe the current, buggy behavior

If a get a table with empty extra row values, I see deprecation warnings in PHP 8.2.

wp post list

+-----+----------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------+---------------------+-------------+
| ID  | post_title                                                                             | post_name                                                                            | post_date           | post_status |
+-----+----------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------+---------------------+-------------+
| 729 | Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor | lorem-ipsum-dolor-sit-amet-consetetur-sadipscing-elitr-sed-diam-nonumy-eirmod-tempor | 2023-07-14 09:49:45 | publish     |
+-----+----------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------+---------------------+-------------+

wp post list

Deprecated: grapheme_strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /parship/lamp/htdocs/vendor/wp-cli/vendor/wp-cli/php-cli-tools/lib/cli/cli.php on line 329
Deprecated: preg_match_all(): Passing null to parameter #2 ($subject) of type string is deprecated in /parship/lamp/htdocs/vendor/wp-cli/vendor/wp-cli/php-cli-tools/lib/cli/cli.php on line 331
Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /parship/lamp/htdocs/vendor/wp-cli/vendor/wp-cli/php-cli-tools/lib/cli/Colors.php on line 215
Deprecated: str_pad(): Passing null to parameter #1 ($string) of type string is deprecated in /parship/lamp/htdocs/vendor/wp-cli/vendor/wp-cli/php-cli-tools/lib/cli/Colors.php on line 218
...
+-----+-------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------+---------------------+-------------+
| ID  | post_title                                                                          | post_name                                                                            | post_date           | post_status |
+-----+-------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------+---------------------+-------------+
| 729 | Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tem | lorem-ipsum-dolor-sit-amet-consetetur-sadipscing-elitr-sed-diam-nonumy-eirmod-tempor | 2023-07-14 09:49:45 | publish     |
|     | por                                                                                 |                                                                                      |                     |             |
+-----+-------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------+---------------------+-------------+

Let us know what environment you are running this on

PHP version: 8.2.7
WP-CLI version: 2.9.0-alpha

Provide a possible solution

https://github.com/wp-cli/php-cli-tools/blob/22270f4e4cafdd72c439150817412b8c04387798/lib/cli/table/Ascii.php#L183

We should check if the array is empty:

$row_values[ $col ] = ! empty( $col_values ) ? array_shift( $col_values ) : '';
danielbachhuber commented 1 year ago

Thanks for the report and suggested fix, @Soean ! I put together a pull request with https://github.com/wp-cli/php-cli-tools/pull/160