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

后端 未结 6 1307
执笔经年
执笔经年 2021-02-09 07:15

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:53

    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 ->.

提交回复
热议问题