How can the object operator be used to access methods and properties of objects in PHP?

To access methods and properties of objects in PHP, you can use the object operator (->). This operator allows you to call methods and access properties of an object. Simply use the object name followed by -> and then the method or property you want to access.

class Person {
    public $name = "John";
    
    public function greet() {
        echo "Hello, my name is " . $this->name;
    }
}

$person = new Person();
echo $person->name; // Accessing property
$person->greet(); // Calling method