How does passing variables to the constructor in PHP differ from Java?

In PHP, passing variables to the constructor is done by defining parameters in the constructor method itself. This allows for flexibility in providing initial values to the object upon instantiation. In Java, passing variables to the constructor is also done by defining parameters in the constructor method, but the syntax and conventions may differ slightly.

class MyClass {
    private $variable;

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

    public function getVariable() {
        return $this->variable;
    }
}

$obj = new MyClass("Hello");
echo $obj->getVariable(); // Output: Hello