Pardon any mistakes in verbiage, I am trying to learn classes.
Once an object has been instantiated, I understand that methods from that class become available to me. My question is, how am I able to run methods from a class other than the instantiated one on said object?
Specifically:
class image {
public static function create() {
$image = new Imagick($file);
$image -> image::autoRotate($image);
...
}
public static function autoRotate($image) {
...
}
}
the line $image -> image::autoRotate($image) yields the error, and I understand the syntax and/or my understanding are at fault. Can someone kindly help me understand how to accomplish this please?
Because the the image
class isn't actually a property of the $image
object, you don't need to use the $image ->
syntax to perform that operation. Since autoRotate()
is a static function, it can be called just from the class accessor image::autoRotate($image);
class image {
public static function create() {
$image = new Imagick($file);
image::autoRotate($image); // removed $image ->
...
}
public static function autoRotate($image) {
...
}
}
public static function can be called directly by classname::funcname
, no need to instantiate an object first. In your case:
class image {
public static function create() {
$image = new Imagick($file);
image::autoRotate($image);
...
}
public static function autoRotate($image) {
...
}
}
Try to replace line ..
$image -> image::autoRotate($image);
with this one..
self::autoRotateImage($image);