require_once to global scope within a function

前端 未结 4 1642
情话喂你
情话喂你 2021-01-11 13:47

It seems that if require_once is called within function, the included file doesn\'t extend the global variable scope. How to require_once a

4条回答
  •  伪装坚强ぢ
    2021-01-11 14:26

    Functions are not an issue (ref):

    All functions and classes in PHP have the global scope - they can be called outside a function even if they were defined inside and vice versa.

    About global variables: As in an existing question regarding the scope of require and the like, the scope is defined where the use is. If you need something else, there are numerous answers (my take) that show how to deal with global variables, most making use of get_defined_vars.

提交回复
热议问题