masterexploder / PHPThumb

PHP Thumbnail & Image Manipulation Library
http://phpthumb.gxdlabs.com
980 stars 264 forks source link

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

Open pmaselkowski opened 7 years ago

pmaselkowski commented 7 years ago

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.

muslimakhan commented 5 years ago

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

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

pmaselkowski commented 5 years ago

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

monter08 commented 5 years ago

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

henrycolonia commented 4 years ago

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.