繁体   English   中英

在类PHP中从一个函数调用另一个函数

[英]Call Function From One Function To Another In A Class PHP

我想在另一个函数中使用类内部的函数。 我试过只是调用它,但它似乎不起作用。 这是我在做什么:

class dog {
    public function info($param) {
        //Do stuff here
    }
    public function call($param2) {
        //Call the info function here
        info($param2);
        //That does not seem to work though, it says info is undefined.
    }
}

因此,基本上我的问题是如何在类中从另一个函数调用函数。 谢谢,我很上课! :d

在PHP中,您始终需要使用$this->来调用类方法(或任何属性)。 在您的情况下,代码为:

public function call($param2) {
        //Call the info function here
        $this->info($param2);
        //That does not seem to work though, it says info is undefined.
}

请注意,如果您将方法声明为静态,则必须使用self::static::

这是一种基本的PHP OOP语法,有关更多信息, 请阅读doc

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM