tecnickcom / TCPDF

Official clone of PHP library to generate PDF documents and barcodes
https://tcpdf.org
Other
4.22k stars 1.52k forks source link

phpversion('imagick') is returning @PACKAGE_VERSION@ instead of the actual version number #445

Open erezhod opened 3 years ago

erezhod commented 3 years ago

I have been using webdevops/php-apache-dev:7.4-alpine as my Docker entry for a year now and it contained Alpine v3.13. Lately I have reset my Docker images completely to start fresh and the php-apache-dev:7.4-alpine image is now using Alpine v3.14.

My problem is that this function from tcpdf_static.php is now throwing ERROR: Imagick::clone is DEPRECATED...:

public static function objclone($object) {
    if (($object instanceof Imagick) AND (version_compare(phpversion('imagick'), '3.0.1') !== 1)) {
        // on the versions after 3.0.1 the clone() method was deprecated in favour of clone keyword
        return @$object->clone();
    }
    return @clone($object);
}

After a research, it appears the php method phpversion('imagick') is returning the literal string @PACKAGE_VERSION@ instead of the actual version number, therefore version_compare() always returns -1, meaning it will always use the deprecated Imagick::clone line of code no matter what.

I have tried using Imagick::getVersion() just for sports and it still returns the same weird @PACKAGE_VERSION@ string.

Is there any fix I can apply to make the phpversion('imagick') return an actual version without forking the TCPDF repo and changing the code myself to not check for older version?

It's worth mentioning it worked fine in Alpine 3.13, but I cannot downgrade anymore for some reason because of the Docker image vendor.

Thank you very much.

bsweeney commented 3 years ago

I believe this happens when the version in use is not a packaged release of IMagick, e.g. built on-system or through a custom build process. Honestly I haven't dug quite that deep into the root cause, but am currently using the following logic to work around the issue:

            // the first version containing it was 3.0.1RC1
            static $imagickClonable = null;
            if ($imagickClonable === null) {
                $imagickClonable = true;
                if (defined('Imagick::IMAGICK_EXTVER')) {
                    $imagickVersion = Imagick::IMAGICK_EXTVER;
                } else {
                    $imagickVersion = '0';
                }
                if (version_compare($imagickVersion, '0.0.1', '>=')) {
                    $imagickClonable = version_compare($imagickVersion, '3.0.1rc1', '>=');
                }
            }

Basically, @PACKAGE_VERSION@ is interpreted as a "0" release. In that scenario we assume the user is using a custom build based on a more recent version of the code.