What best practices should be followed when declaring and using class properties in PHP?

When declaring and using class properties in PHP, it is best practice to define them as private or protected to encapsulate the data and prevent direct access from outside the class. Additionally, it is recommended to provide getter and setter methods to control access to the properties and ensure data integrity. Using type hinting and default values for properties can also help improve code readability and maintainability.

class MyClass {
    private $name;
    
    public function getName(): string {
        return $this->name;
    }
    
    public function setName(string $name): void {
        $this->name = $name;
    }
}