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

后端 未结 6 1305
执笔经年
执笔经年 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:44

    You can simply create variables in a PHP file say named Constants.

    --Constants.php-- $DATABASE_NAME = "mysql"

    and include the file in your file. You can change its value. It comes close to what you want, but it is not good call them constants because constants aren't meant to be changed, that's what confused me :).

提交回复
热议问题