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.variable = variable

    def otherfunc(self):
        print self.variable

Upvotes: 2

Views: 1930

Answers (2)

user212218
user212218

Reputation:

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

Upvotes: 8

Cydonia7
Cydonia7

Reputation: 3826

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

Upvotes: 2

Related Questions