What is the scope of require_once in PHP?

后端 未结 4 1569
故里飘歌
故里飘歌 2021-01-08 01:08

Simple question: Is the scope of require_once global?

For example:



        
4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-08 01:41

    To more specifically answer your question, the second time you call require_once on that file, it won't do anything, because it's already be included.

    If your include has functions etc. in it, then you would have issues including it inside a function anyway, so scope is irrelevant. If it's just variables being defined or processed, then you can just use require instead of require_once if you want it to be included again, thereby redefining the variables in your scope.

提交回复
热议问题