Global vs static variables in PHP

前端 未结 3 1395
梦谈多话
梦谈多话 2021-01-11 13:55

I\'m creating a basic framework in PHP. I need to pass data for the current page into different functions, allow them to modify and save it, and then pass it back to the pag

3条回答
  •  长情又很酷
    2021-01-11 14:55

    There really is no difference between a global variable and a public static variable. The class variable is namespaced a tiny bit better, but that hardly makes any difference. Both are accessible anywhere at any time and both are global state.

    As it happens, I just wrote an exhaustive article on the subject:
    How Not To Kill Your Testability Using Statics

提交回复
热议问题