The operator @
is used to suppress error messages. It may even be that the code that depends on this method is already wrong in time, even in PHP 5.
In that case I would remove the @
to ensure that everything is working. It is possible to include other type checks in order to ensure that when arriving at the clone
no major problems.
You can for example add a hinting type of object
to ensure that only objects will be passed to this method (works from PHP 7.2):
public static function objclone(object $object) {
}
In this case when using an invalid type you will know where you need to store.
Another less disruptive approach is to check the type of the variable and if it is not an object return the variable itself, because the clone
only works with objects and return a primitive variable is similar to clone behavior (in PHP only objects receive a reference in assignment):
public static function objclone($object) {
if (!is_object($object)) {
return $object;
}
// ...
}
Another option that can give more work, check if you really need to make a clone of the objects. In addition to improving memory consumption, your code will be more readable. And if you need to use directly clone
instead of calling the function.
Last but not least, confirm the correct version of Imagick. According to documentation of that method, it was discontinued in version 3.1.0, not in version 3.0.1.
Try changing your code to use this version. In a compiled version, your method can look like this:
public static function objclone($object) {
if (!is_object($object)) {
// If is not an object, return the variable itself
return $object;
}
if (($object instanceof Imagick) && (version_compare(phpversion('imagick'), '3.1.0') !== 1)) {
// clone() method was deprecated in favor of clone keyword
// see https://www.php.net/manual/en/imagick.clone.php
return $object->clone();
}
return clone $object;
}
At some point the
imagick
in those old versions?– Woss
Yes, it is still used.
clone()
of a non-existent object is missing error– ALE_ROM
errata *fatal error
– ALE_ROM