What are common pitfalls when using assign-op operators with overloaded objects or string offsets in PHP?

Common pitfalls when using assign-op operators with overloaded objects or string offsets in PHP include unexpected behavior due to the way PHP handles these operations. To solve this issue, it is recommended to explicitly define the behavior of assign-op operators for overloaded objects or string offsets within the class definition by implementing the magic methods __get() and __set().

class MyClass {
    private $data = [];

    public function __get($key) {
        return $this->data[$key];
    }

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

$obj = new MyClass();
$obj->prop = 10; // This will correctly set the value of 'prop' in the object