开发者

In PHP classes, what is the equivalent of self from python classes?

In PHP, how can I achieve something like this from Python?

class CrowdProcess():
    def __init__(self,variable):
        self.开发者_StackOverflow社区variable = variable

    def otherfunc(self):
        print self.variable


PHP uses $this as a reference to the instance:

class CrowdProcess
{
    public $variable;

    public function __construct($variable)
    {
        $this->variable = $variable;
    }

    public function otherfunc()
    {
        echo $this->variable, PHP_EOL;
    }
}

For more information, see http://php.net/language.oop5.basic#example-155


You can use $this->variable in PHP :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜