When should I declare variables in a PHP class?

前端 未结 6 1008
小鲜肉
小鲜肉 2020-11-30 03:06

I\'m new to the OOP paradigm, so there\'s probably a simple explanation for this question...

Do you always need to declare public object-wide variables in a class? F

6条回答
  •  独厮守ぢ
    2020-11-30 03:19

    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.

提交回复
热议问题