What's the PHP equivalent of a static variable in other languages?

后端 未结 6 911
逝去的感伤
逝去的感伤 2021-02-09 07:03

I\'m wondering if PHP has a type of variable in classes that functions like static in other languages. And by that I mean all objects of the same class use the same variable and

6条回答
  •  名媛妹妹
    2021-02-09 07:40

    The correct answer is that there is no equivalent in PHP to final, but static seems like what you wanted in the first place anyway.

    static has the property that it will have the same value across all instances of a class, because it is not tied to a particular instance.

    You will need to use the :: operator to access it, because being static, you cannot use ->.

提交回复
热议问题