rosell-dk / webp-convert

Convert jpeg/png to webp with PHP (if at all possible)
MIT License
580 stars 102 forks source link

Argument must be of type array|object, int given | PHP 8 #295

Closed satellasoft closed 3 years ago

satellasoft commented 3 years ago

Hi everyone!

We are implementing the lib in a project that runs through PHP 8, but without success due to warning and Fatal Error.

Code block:

$source = $this->path . $image;

$destination = $this->path . strtolower($data[1]) . '.webp';

$quality = 90;
$stripMetadata = true;

WebPConvert::convert($source, $destination, $quality, $stripMetadata);

This project has been install by Composer using last package version.

Log message:

Warning: foreach() argument must be of type array|object, int given in C:\xampp****\vendor\rosell-dk\webp-convert\src\Convert\Converters\BaseTraits\OptionsTrait.php on line 154

Warning: foreach() argument must be of type array|object, int given in C:\xampp****\vendor\rosell-dk\webp-convert\src\Convert\Converters\BaseTraits\OptionsTrait.php on line 161

Fatal error: Uncaught Error: Call to a member function log() on bool in C:\xampp****\vendor\rosell-dk\webp-convert\src\Convert\Converters\BaseTraits\LoggerTrait.php:68 Stack trace: #0 C:\xampp****\vendor\rosell-dk\webp-convert\src\Convert\Converters\AbstractConverter.php(123): WebPConvert\Convert\Converters\AbstractConverter->log('WebP Convert 2....', 'italic') #1 C:\xampp****\vendor\rosell-dk\webp-convert\src\Convert\Converters\AbstractConverter.php(205): WebPConvert\Convert\Converters\AbstractConverter->__construct('img/artigos/202...', 'img/artigos/202...', 90, true) #2 C:\xampp****\vendor\rosell-dk\webp-convert\src\Convert\Converters\AbstractConverter.php(355): WebPConvert\Convert\Converters\AbstractConverter::createInstance('img/artigos/202...', 'img/artigos/202...', 90, true) #3 C:\xampp****\vendor\rosell-dk\webp-convert\src\WebPConvert.php(43): WebPConvert\Convert\Converters\AbstractConverter::convert('img/artigos/202...', 'img/artigos/202...', 90, true) #4 C:\xampp****\app\classes\ImageConvert.php(91): WebPConvert\WebPConvert::convert('img/artigos/202...', 'img/artigos/202...', 90, true) #5 C:\xampp****\app\classes\ImageConvert.php(32): App\classes\ImageConvert->convertToWebP(Array, 'img/artigos/202...') #6 C:\xampp****\app\sites\author\controller\ArtigoController.php(182): App\classes\ImageConvert->convertAllByPath() #7 [internal function]: app\sites\author\controller\ArtigoController->uploadImages('2021-01-30') #8 C:\xampp****\app\core\RouterCore.php(112): call_user_func_array(Array, Array) #9 C:\xampp****\app\core\RouterCore.php(30): app\core\RouterCore->execute() #10 C:\xampp****\public\index.php(4): app\core\RouterCore->__construct() #11 {main} thrown in C:\xampp****\vendor\rosell-dk\webp-convert\src\Convert\Converters\BaseTraits\LoggerTrait.php on line 68