JamesHeinrich / phpThumb

phpThumb() - The PHP thumbnail generator
Other
315 stars 97 forks source link

PHP 8 TypeError in round() because of string arg #169

Closed alpenbytes closed 2 years ago

alpenbytes commented 3 years ago

When using phpThumb with only one url dimension parameter, i.e. "?src=x&h=300&hash=x" the following PHP 8 Error is thrown: Fatal error: Uncaught TypeError: round(): Argument #1 ($num) must be of type int|float, string given in PATH\vendor\james-heinrich\phpthumb\phpthumb.class.php:1922

The issue occurs when only "height" OR "width" is set. I nailed it down to the code a few lines above on line 1910 and 1911:

$this->w = (($this->aoe && $this->w) ? $this->w : ($this->w ? phpthumb_functions::nonempty_min($this->w, $getimagesize[0]) : ''));
$this->h = (($this->aoe && $this->h) ? $this->h : ($this->h ? phpthumb_functions::nonempty_min($this->h, $getimagesize[1]) : ''));

As $this->w is originally FALSE when not set, this line sets it to an empty string which now breaks round() on line 1922.

The issue can be fixed when the above code lines are populating $this->w / $this->h with NULL instead of empty string as NULL is an acceptable arg for round(). But I don't know why the code lines are setting to empty string in the first place instead of NULL. Is it safe to change this in an PR to NULL?

JamesHeinrich commented 3 years ago

If changing empty-string to NULL fixed the problem, I have no problem with that.

alpenbytes commented 2 years ago

Fixed with #177