dongzhuo3202 2016-06-09 17:12
浏览 27
已采纳

如何从非实例类的实例上运行方法/函数?

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?

  • 写回答

3条回答 默认 最新

  • dongtiao0657 2016-06-09 17:17
    关注

    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) {
        ...
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持