What are the alternatives to using "normal" getter and setter methods for a large number of attributes in PHP classes?

When dealing with a large number of attributes in PHP classes, using traditional getter and setter methods can become cumbersome and lead to code duplication. An alternative approach is to use PHP's magic methods __get() and __set() to dynamically handle property access and modification.

class MyClass {
    private $data = [];

    public function __get($name) {
        if (array_key_exists($name, $this->data)) {
            return $this->data[$name];
        }
        return null;
    }

    public function __set($name, $value) {
        $this->data[$name] = $value;
    }
}

// Usage
$obj = new MyClass();
$obj->attribute1 = 'value1';
echo $obj->attribute1; // Output: value1