Error: Unsupported operand types: string - int in Drupal\entity_update\EntityUpdatePrint::drushPrintTable()

Created on 18 February 2023, over 1 year ago
Updated 27 February 2023, over 1 year ago

Problem/Motivation

I've installed entity_update (3.0.0-rc2, installed via composer), for a Drupal 9.5.3 installation. This is running under PHP 8.1.12.

Running drush upec --types results in a PHP error: "Unsupported operand types: string - int".

<!--break-->

The following information displayed:

sh: tput: not found
 [error]  TypeError: Unsupported operand types: string - int in Drupal\entity_update\EntityUpdatePrint::drushPrintTable() (line 114 of /var/www/html/web/modules/contrib/entity_update/src/EntityUpdatePrint.php) #0 /var/www/html/web/modules/contrib/entity_update/src/EntityCheck.php(46): Drupal\entity_update\EntityUpdatePrint::drushPrintTable() 

Steps to reproduce

Install the module on a platform with PHP 8, with no tput utility installed (e.g., Alpine Linux, popular as a base for docker PHP containers). Run drush upec --types.

Proposed resolution

The error is caused when exec('tput cols') fails, because tput does not exist on the platform.
The result is a null string, which causes a type error in PHP 8 when the expression $cols - 2 is evaluated.

Note: earlier versions of PHP will not throw an error, but produce nonsensical (e.g. negative) results for $cols - 2 .

A solution is to check the result of the call to tput. If this fails, try to call stty size, which often exists when tput is not present. Finally, if neither of those returns a useful result, supply a default width.

Remaining tasks

I will supply a patch which implements the proposed resolution. Let's test this across multiple PHP versions / platforms.

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇨🇦Canada puregin

Live updates comments and jobs are added and updated live.
  • PHP 8.0

    The issue particularly affects sites running on PHP version 8.0.0 or later.

  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024