PHPThumb icon indicating copy to clipboard operation
PHPThumb copied to clipboard

[PHP 7.2] sizeof(): Parameter must be an array or an object that implements Countable

Open pmaselkowski opened this issue 8 years ago • 4 comments

I know that this project seems abandoned... But here's the issue with sizeof:

                                                                                                             
  [PHPUnit_Framework_Exception] sizeof(): Parameter must be an array or an object that implements Countable  
                                                                                                             
#1  Codeception\Subscriber\ErrorHandler->errorHandler
#2  /home/travis/build/Maslosoft/Mangan/vendor/masterexploder/phpthumb/src/PHPThumb/GD.php:972
#3  /home/travis/build/Maslosoft/Mangan/vendor/masterexploder/phpthumb/src/PHPThumb/PHPThumb.php:64
#4  /home/travis/build/Maslosoft/Mangan/vendor/masterexploder/phpthumb/src/PHPThumb/GD.php:89
#5  /home/travis/build/Maslosoft/Mangan/src/Model/Image.php:101
#6  /home/travis/build/Maslosoft/Mangan/src/Model/File.php:145
#7  /home/travis/build/Maslosoft/Mangan/vendor/maslosoft/mangantest/tests/unit/GridFS/ImageTest.php:34
#8  GridFS\ImageTest->testIfWillResizeSavedImage

The problem is that options are defined without value:

    protected $options;

So in fact are initialized with null, not empty array.

Then there is check for array size with sizeof (alias for count).

Workaround

Create class:

class ImageThumb extends GD
{
	protected $options = [];
}

And use this new class instead of GD.

pmaselkowski avatar Sep 08 '17 12:09 pmaselkowski

Resolved, check this https://github.com/masterexploder/PHPThumb/pull/134

https://github.com/masterexploder/PHPThumb/pull/134/commits/a02b4b77bd78a24b80f1a3e1653466de9b235d5b

muslimakhan avatar Oct 05 '18 11:10 muslimakhan

@MuslimAKhan Are You capable of (ie, have permissions?) to create tag with this fix so that it would allow installing it with composer?

pmaselkowski avatar Oct 10 '18 14:10 pmaselkowski

Everyone who have this issue and using composer:

Add to composer.json "repositories": [ { "type": "vcs", "url": "https://github.com/monter08/PHPThumb" }]

and composer update masterexploder/phpthumb

monter08 avatar Jul 15 '19 09:07 monter08

Hello, is there a way for this change to be present in version 2.1 shown at https://packagist.org/packages/masterexploder/phpthumb#2.1 ?. I understand that it can be obtained from the version " dev-master ", but I am using an external library that requires any version of this project that starts with" 2. * ", so updating against" dev-master "generates conflicts for me.

Thanks.

henrycolonia avatar Apr 22 '20 17:04 henrycolonia