在PHP中,我如何从Python中实现这样的东西?
class CrowdProcess():
def __init__(self,variable):
self.variable = variable
def otherfunc(self):
print self.variable
答案 0 :(得分:8)
PHP使用$this
作为对实例的引用:
class CrowdProcess
{
public $variable;
public function __construct($variable)
{
$this->variable = $variable;
}
public function otherfunc()
{
echo $this->variable, PHP_EOL;
}
}
答案 1 :(得分:2)
您可以在PHP中使用$this->variable
:)