How does the "->" operator work in accessing methods or properties of a class in PHP?
The "->" operator is used in PHP to access methods or properties of a class instance. It is placed between the object variable and the method or property name that we want to access. This operator allows us to interact with the object's methods and properties, enabling us to manipulate the object's behavior and data. Example:
class MyClass {
public $property = "Hello";
public function myMethod() {
echo $this->property;
}
}
$obj = new MyClass();
$obj->myMethod(); // Output: Hello