How can a parameter be passed to a constructor when creating an instance of a class in PHP?

When creating an instance of a class in PHP, you can pass parameters to the constructor by defining the parameters in the constructor method of the class. This allows you to initialize the object with specific values or configurations when it is instantiated. Example:

class MyClass {
    private $parameter;

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

    public function getParameter() {
        return $this->parameter;
    }
}

// Creating an instance of MyClass with a parameter
$instance = new MyClass('Hello, World!');

// Getting the parameter value from the instance
echo $instance->getParameter(); // Output: Hello, World!