PHP 5: const vs static

前端 未结 7 837
长情又很酷
长情又很酷 2020-11-29 16:38

In PHP 5, what is the difference between using const and static?

When is each appropriate? And what role does public, pr

7条回答
  •  既然无缘
    2020-11-29 17:28

    Declaring a class method or property as static makes them accessible without needing an instantiation of the class.

    A class constant is just like a normal constant, it cannot be changed at runtime. This is also the only reason you will ever use const for.

    Private, public and protected are access modifiers that describes who can access which parameter/method.

    Public means that all other objects gets access. Private means that only the instantiated class gets access. Protected means that the instantiated class and derived classes gets access.

提交回复
热议问题