在PHP类中,python类中的self的等价物是什么?

在PHP类中,python类中的self的等价物是什么?,php,python,class,self,Php,Python,Class,Self,在PHP中,如何从Python实现类似的功能 class CrowdProcess(): def __init__(self,variable): self.variable = variable def otherfunc(self): print self.variable 您可以在PHP:)中使用$this->variablePHP使用$this作为实例的引用: class CrowdProcess { public $varia

在PHP中,如何从Python实现类似的功能

class CrowdProcess():
    def __init__(self,variable):
        self.variable = variable

    def otherfunc(self):
        print self.variable

您可以在PHP:)中使用
$this->variable

PHP使用
$this
作为实例的引用:

class CrowdProcess
{
    public $variable;

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

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

有关更多信息,请参见

然后我是否可以调用$CP=new CrowdProcess(“定义变量”);希望构造中的$this->变量变成“定义变量”?无需回答,我试过了,它做到了:)谢谢你的“翻译”!我继续添加了一个链接,您可能会发现它很有用。祝你快乐(: