PHP include/require inside functions

后端 未结 4 1115
一个人的身影
一个人的身影 2020-12-18 21:24

Having functions that are quite big and they are loading every time the page is loaded, would be better to write function foo(){ include(.../file_with_function\'s_code

4条回答
  •  情书的邮戳
    2020-12-18 22:12

    Yes that's possible; see http://www.php.net/manual/en/function.include.php

    If the include occurs inside a function within the calling file, then all of the code contained in the called file will behave as though it had been defined inside that function. So, it will follow the variable scope of that function.

    Question is, why not add the surrounding function definition to that included file. I think the only viable reason to include within a function is to split code within that function into bits.

提交回复
热议问题