Fatal error - 'object that implements Countable in PHPVideoToolkit'

Created on 12 March 2019, over 5 years ago
Updated 16 June 2023, over 1 year ago

Error report from Drupal logging:

Parameter must be an array or an object that implements Countable in PHPVideoToolkit->setInputFile() (line 1152 of /usr/share/nginx/html/sites/all/modules/video/libraries/phpvideotoolkit/phpvideotoolkit.php5.php).

Environment: CentOS7

Mitigation attempted has included reinstallin ffmpeg (there are no codec errors, and this same error occurs on all of the presets from the Video Presets module), triple checking the path, changing /tmp to 777.

Looking at the code, this errors occurs on the following code:

$files_length = count($file);

I understand looking through Drupal errors for the term 'Parameter must be an array or an object that implements Countable' that PHP 7.2 depreciated checking for empty from count().

A thorough look through the Video error issue queue doesn't reveal anything.

This error blocks transcoding video, so I've marked as high (blocking core functionality).

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡¨πŸ‡³China zhte415

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

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

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 7.x + Environment: PHP 7.1.x-dev & MySQL 5.5
    last update over 1 year ago
    15 pass
  • πŸ‡ΈπŸ‡°Slovakia poker10

    Thanks for working on this!

    The if-else condition works only with these two possible scenarios:

    //if the total number of files entered is 1 then only one file is being processed
    if ($files_length == 1) {
    
    else {
    //more than one video is being added as input so we must join them all
    

    So even though the patch #3 is correct, I do not think it would be good to introduce possibility to evaluate the $files_length variable to zero. If we allow that, it would means that it will end up in the else branch supposed to work with array, but actually the $file would be an empty string (or similar). It can cause unpredicted behavior.

    So I propose to change the fix from:

    $files_length = is_array($file) || $file instanceof Countable ? count($file) : (int) (!empty($file));
    

    to:

    $files_length = is_array($file) || $file instanceof Countable ? count($file) : 1;
    

    This will ensure that if the $file would be empty, it would be handled correctly in the if branch, see:

    if (!preg_match('/\%([0-9]+)d/', $file) && strpos($file, '%d') === FALSE && !is_file($file)) {
      //input file not valid
      return $this->_raiseError('setInputFile_file_existence', array('file' => $file));
    }
    

    I am going to commit the modified version of the patch to fix the problem.

  • Status changed to Fixed over 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024