Check if a file was included or loaded

后端 未结 12 1212
轻奢々
轻奢々 2020-12-08 13:35

Is there any elegant way to check if a file was included by using include/include_once/require/require_once or if the pag

12条回答
  •  情深已故
    2020-12-08 13:46

    get_included_files() return array where 0 index mean first "included" file. Because direct run mean "include" in this terms, you can simple check first index for equality for __FILE__:

    if(get_included_files()[0] == __FILE__){
        do_stuff();
    }
    

    This can not work on PHP 4, because PHP 4 not add run file in this array.

提交回复
热议问题