Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would a loaded PHP extension fail on class instantiation?

I have some code which is resizing images, using either Imagick or GD, depending what's available on the server.

I'm testing for availability of each using the extension_loaded() function.

if (extension_loaded('imagick')) {
    $image = new Imagick();
    ...
}

I have one user reporting that they are receiving:

Fatal error: Class 'Imagick' not found

What circumstances would result in the Imagick extension being loaded but the class not available? How should I be testing to make my code more robust?

like image 244
drewm Avatar asked Dec 04 '25 17:12

drewm


1 Answers

1: always do the checks in a case-insensitive manner (make the string lowercase before comparing it)

2: don't check for the library, check for features. Maybe it has a library version that's buggy or has other function names

3: in php.ini you may disable some functions explicitly by name so I think you should resort to point #2 and check with function_exists instead of extension_*

Also, take a look at /var/log/apache2/errors or the equivalent on that client's server to check for any internal error generated by the ImageMagick extension (segmentation fault or other types of low-level errors should get reported in there...)

like image 197
Quamis Avatar answered Dec 07 '25 20:12

Quamis