What is the purpose of the __isset() method in PHP classes?

The __isset() method in PHP classes is used to determine if a certain property is set or not within an object. This method is automatically called when isset() is used on an object property. By implementing the __isset() method in a class, you can customize the behavior of isset() when checking for the existence of properties.

class MyClass {
    private $data = array();

    public function __isset($name) {
        return isset($this->data[$name]);
    }
}

$object = new MyClass();
$object->data['name'] = 'John';

var_dump(isset($object->name)); // Output: bool(true)
var_dump(isset($object->age)); // Output: bool(false)