How does PHP handle variable initialization in classes, especially in versions 7.4 and above?

In PHP versions 7.4 and above, class properties can be initialized directly in the class definition. This helps to improve code readability and reduces the need to initialize variables in the constructor. To initialize variables in classes in PHP 7.4 and above, simply assign the default value directly to the property within the class definition.

class MyClass {
    public string $name = 'John Doe';
    public int $age = 30;
}