global variables in php not working as expected

后端 未结 7 1808
被撕碎了的回忆
被撕碎了的回忆 2020-12-05 07:33

I\'m having trouble with global variables in php. I have a $screen var set in one file, which requires another file that calls an initSession() def

7条回答
  •  时光取名叫无心
    2020-12-05 07:48

    global $foo doesn't mean "make this variable global, so that everyone can use it". global $foo means "within the scope of this function, use the global variable $foo".

    I am assuming from your example that each time, you are referring to $screen from within a function. If so you will need to use global $screen in each function.

提交回复
热议问题