Should require_once “some file.php” ; appear anywhere but the top of the file?

前端 未结 5 884
时光取名叫无心
时光取名叫无心 2021-01-05 23:32

Is the following example appropriate for PHP\'s require_once construct?

function foo( $param )
{
    require_once \"my_file.php\" ;
    //
    // do somethin         


        
5条回答
  •  情深已故
    2021-01-06 00:12

    It comes down to a matter of coding style and opinion. Personally I keep all my require_once statements at the very top of my files so I can easily see which files are included where, nothing worse then some buried include messing with your scripts. However, if you have several large required scripts that are only required for certain functions, then putting the require_once inside a function would be OK from a performance stand-point, just make sure to put a note at the top of the page.

提交回复
热议问题