When should I declare variables in a PHP class?

That variable isn’t uninitialized, it’s just undeclared.

Declaring variables in a class definition is a point of style for readability.
Plus you can set accessibility (private or public).

Anyway, declaring variables explicitly has nothing to do with OOP, it’s programming-language-specific. In Java you can’t do that because variables must be declared explicitly.

Leave a Comment