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

后端 未结 6 910
逝去的感伤
逝去的感伤 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:58

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

提交回复
热议问题