在 PHP 中,我怎样才能从 Python 实现类似的东西?
class CrowdProcess():
def __init__(self,variable):
self.variable = variable
def otherfunc(self):
print self.variable
最佳答案
PHP 使用 $this
作为对实例的引用:
class CrowdProcess
{
public $variable;
public function __construct($variable)
{
$this->variable = $variable;
}
public function otherfunc()
{
echo $this->variable, PHP_EOL;
}
}
关于php - 在 PHP 类中,python 类中的 self 等价于什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7084564/