safe icon indicating copy to clipboard operation
safe copied to clipboard

GD extension - resource is replaced by GdImage in PHP8

Open dbrekelmans opened this issue 4 years ago • 3 comments

In a lot of GD extension functions, the previously passed resource has been replaced by GdImage in PHP8. Our docblocks are incorrect. (see: https://github.com/thecodingmachine/safe/blob/master/generated/image.php)

dbrekelmans avatar Jul 28 '21 11:07 dbrekelmans

This is really annoying, especially if you use static analysis.

nreynis avatar Sep 13 '22 13:09 nreynis

yes, hitting this issue. Any sensible workarounds?

I'm using safe + rector + phpstan, and PHPstan aint happy at all

For reference, my current approach is to use some type forcing comments, eg

/** @var GdImage $image */
            $image = match ($this->sourceImageExtension) {
                self::EXT_WEBP => \Safe\imagecreatefromwebp($this->sourceImageUrl),
                self::EXT_PNG  => \Safe\imagecreatefrompng($this->sourceImageUrl),
                self::EXT_JPG  => \Safe\imagecreatefromjpeg($this->sourceImageUrl),
                default        => throw new RuntimeException(
                    'Unexpected source image extension "' . $this->sourceImageExtension . '"'
                )
            };

and then a liberal sprinkling of

/** @phpstan-ignore-next-line wrong docblocks in safe */

it's ugly but works for now

ballidev avatar Oct 18 '23 14:10 ballidev