How does PHP handle accessing objects like arrays?

PHP handles accessing objects like arrays by using the arrow (->) operator to access object properties or methods. This allows you to retrieve or modify data within an object instance. To access elements within an object that behaves like an array, you can use the object as if it were an associative array, using the arrow operator to access its properties.

// Creating an object that behaves like an array
$obj = new stdClass();
$obj->key1 = 'value1';
$obj->key2 = 'value2';

// Accessing object properties like an array
echo $obj->key1; // Output: value1
echo $obj->key2; // Output: value2