What are the best practices for using method chaining in PHP to set properties in different objects?

When using method chaining in PHP to set properties in different objects, it is important to ensure that each method call returns the object instance to allow for chaining. This can be achieved by having each setter method return $this. Additionally, it is important to maintain a clear and logical order of method calls to set the properties in the desired objects.

class ObjectA {
    private $propertyA;

    public function setPropertyA($value) {
        $this->propertyA = $value;
        return $this;
    }
}

class ObjectB {
    private $propertyB;

    public function setPropertyB($value) {
        $this->propertyB = $value;
        return $this;
    }
}

// Example of method chaining to set properties in different objects
$objectA = new ObjectA();
$objectB = new ObjectB();

$objectA->setPropertyA('ValueA')
        ->setPropertyB('ValueB');