What are the best practices for declaring and using objects in PHP classes?

When declaring and using objects in PHP classes, it is recommended to follow best practices to ensure clean and maintainable code. This includes declaring objects with proper visibility (public, private, protected), initializing objects in the constructor, and using dependency injection to pass objects into classes rather than creating them internally.

class MyClass {
    private $dependency;

    public function __construct(DependencyClass $dependency) {
        $this->dependency = $dependency;
    }

    public function someMethod() {
        $this->dependency->doSomething();
    }
}

$dependency = new DependencyClass();
$myClass = new MyClass($dependency);
$myClass->someMethod();