How can the pseudo-variable $this be used to access functions and variables within a class?
To access functions and variables within a class in PHP, you can use the pseudo-variable $this. $this refers to the current instance of the class and allows you to access its properties and methods. By using $this followed by the arrow operator (->), you can call class methods and access class variables from within the class.
class MyClass {
public $myVariable = 'Hello';
public function myFunction() {
echo $this->myVariable;
}
}
$obj = new MyClass();
$obj->myFunction(); // Output: Hello