By use of the this
keyword.
<?php
class myClass {
public $foo = 4;
private $bar = 5;
function baz() {
echo $this->foo;
echo $this->bar;
}
}
?>
Will echo both variables of the class, public and private. Private variables, however, cannot be accessed directly from outside of the objects namespace.
By use of the self
keyword.
class myClass:
foo = 4
def baz():
print(self.foo)