Fix undefined variable in Imagick::valid

Fixes #3682