rosell-dk / webp-convert

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

WarningLoggintrait call to drupal_error_handler cause too few arguments fatal error #266

Closed Canguilhem closed 3 years ago

Canguilhem commented 3 years ago

Hello there,

I use https://github.com/HDDen/Webp-Drupal-7 for webp image conversion in a drupal site, conversion works fine though every time drupal catch an error it goes through vendor/rosell-dk/webp-convert/src/Convert/Converters/BaseTraits/WarningLoggerTrait.php and at some point return call_user_func($this->previousErrorHandler, $errno, $errstr, $errfile, $errline); use drupal_error_handler which expect 5 arguments but this call_user_func only sends 4 which cause a too few arguments fatal error, any leads on how to prevent this?

for reference : _drupal_error_handler_real($error_level, $message, $filename, $line, $context)

rosell-dk commented 3 years ago

The $context parameter has been deprecated. Excerpt from PHP docs:

Warning: This parameter has been DEPRECATED as of PHP 7.2.0, and REMOVED as of PHP 8.0.0. If your function defines this parameter without a default, an error of "too few arguments" will be raised when it is called.

What drupal does it exactly that: It defines an error handler with that deprecated parameter, without supplying a default value. The drupal error handler should be changed so it provides a default value for the parameter.

Being that the parameter is deprecated, it seems it would be a bad idea to implement it. However, it would be preferable if webp-convert can avoid these kind of problems. And well, actually it can. There is no such thing as supplying too many parameters to PHP functions, so simply supplying the extra parameter should solve the problem :)