DivaVocals / zen_Image-Handler

Image Handler 4 is really meant to ease the management of product images (particularly the management of additional product images), and to help improve page performance by optimizing the product images.
GNU General Public License v2.0
7 stars 13 forks source link

bmz_image_handler.class: php fatal errors due to wrong types in strict_types mode #233

Closed torvista closed 2 years ago

torvista commented 2 years ago

php8, strict reporting, set declare(strict_types=1); at start of file. Delete contents of bmz_cache to force image generation. Refresh product info page.

PHP Fatal error: Uncaught TypeError: imagecreatetruecolor(): Argument #2 ($height) must be of type int, float given in \tienda\includes\classes\bmz_image_handler.class.php:761

$tmpimg = imagecreatetruecolor($newwidth, $newheight);

And if those values are cast, next refresh leads to PHP Fatal error: Uncaught TypeError: imagecopyresampled(): Argument #8 ($dst_height) must be of type int, float given in includes\classes\bmz_image_handler.class.php:779

and so it goes on....hence some source casting needed.

I note 779 still has a silence operator.

lat9 commented 2 years ago

Was there no backtrace associated with those fatal errors?

lat9 commented 2 years ago

I'm seeing a bunch of places where image widths and heights are calculated, thus creating that float input. I'll continue review and see if this/these issues can be 'nipped in the bud'.

lat9 commented 2 years ago

The underlying issue was the lack of casting in the image's width and height calculations. Starting with PHP 8.0.0, with its input hints, the float type inputs for those parameters are now rejected.

Casting each of the calculated width and height values back to their integer values corrects those issues.