What are the best practices for passing parameters in the constructor of a PHP class?

When passing parameters in the constructor of a PHP class, it is considered a best practice to use type hinting to ensure that the correct data types are being passed. This helps to prevent unexpected errors and improves the readability of the code. Additionally, setting default parameter values can provide flexibility when creating instances of the class.

class MyClass {
    private $param1;
    private $param2;

    public function __construct(string $param1, int $param2 = 0) {
        $this->param1 = $param1;
        $this->param2 = $param2;
    }

    public function getParams() {
        return [$this->param1, $this->param2];
    }
}

// Creating an instance of MyClass with parameters
$myInstance = new MyClass('Hello', 10);
$params = $myInstance->getParams();
print_r($params); // Output: Array ( [0] => Hello [1] => 10 )