What are some potential pitfalls when using method chaining in PHP?

One potential pitfall when using method chaining in PHP is that it can make the code harder to read and debug, especially if there are multiple method calls in a single line. To mitigate this, it's important to use method chaining judiciously and ensure that the code remains clear and maintainable.

// Avoid chaining too many methods in a single line
$result = $object->method1()->method2()->method3();
```

Another potential issue is that if one of the methods in the chain returns a null value, it can cause a fatal error when trying to call a method on that null value. To prevent this, it's a good practice to check for null values before continuing with the method chaining.

```php
// Check for null values before continuing method chaining
$result = $object->method1();

if ($result !== null) {
    $result->method2()->method3();
}