What are some best practices for object instantiation and inheritance in PHP?

When working with object instantiation and inheritance in PHP, it is important to follow best practices to ensure clean and efficient code. One common practice is to use constructors to initialize object properties and ensure that parent class constructors are called when extending classes. Additionally, it is recommended to use type hinting to enforce the correct types of arguments passed to methods.

// Example of object instantiation and inheritance best practices in PHP

class Animal {
    protected $name;

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

    public function getName() {
        return $this->name;
    }
}

class Dog extends Animal {
    private $breed;

    public function __construct($name, $breed) {
        parent::__construct($name);
        $this->breed = $breed;
    }

    public function getBreed() {
        return $this->breed;
    }
}

$dog = new Dog('Buddy', 'Golden Retriever');
echo $dog->getName(); // Output: Buddy
echo $dog->getBreed(); // Output: Golden Retriever