[英]In PHP classes, what is the equivalent of self from python classes?
In PHP, how can I achieve something like this from Python?在 PHP 中,我怎样才能从 Python 实现这样的事情?
class CrowdProcess():
def __init__(self,variable):
self.variable = variable
def otherfunc(self):
print self.variable
PHP uses $this
as a reference to the instance: PHP 使用
$this
作为对实例的引用:
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有关详细信息,请参阅http://php.net/language.oop5.basic#example-155
You can use $this->variable
in PHP:)您可以在 PHP 中使用
$this->variable
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.