What are common pitfalls when accessing and working with objects in PHP?

One common pitfall when accessing objects in PHP is trying to access properties or methods that do not exist, resulting in errors. To avoid this, always check if the property or method exists before trying to access it. You can use the `property_exists` and `method_exists` functions to check for the existence of properties and methods respectively.

// Check if a property exists before accessing it
if(property_exists($object, 'propertyName')) {
    $value = $object->propertyName;
}

// Check if a method exists before calling it
if(method_exists($object, 'methodName')) {
    $object->methodName();
}