include, include_once, require or require_once?

前端 未结 8 1179
误落风尘
误落风尘 2020-11-27 17:21

I have PHP file where I have defined the server access variables as well as the mysql_connect and mysql_select_db, as this functions are regularly

8条回答
  •  北海茫月
    2020-11-27 17:42

    Functional Work : All functions perform similar work. All functions will include and evaluates the specific file while executing the code.

    Functional Difference :

    include vs include_once : There is only one difference between include() and include_once(). If the code from a file has been already included then it will not be included again if we use include_once(). Means include_once() include the file only once at a time.

    include vs require : if include() is not able to find a specified file on location at that time it will throw a warning however, it will not stop script execution. For the same scenario, require() will throw a fatal error and it will stop the script execution.

    require vs require_once : There is only one difference between require() and require_once(). If the code from a file has been already included then it will not be included again if we use require_once(). Means require_once() include the file only once at a time.

    To get the detailed knowledge with example please review these amazing articles
    (1) http://www.readmyviews.com/include-vs-include-once/
    (2) http://www.readmyviews.com/include-vs-require/

提交回复
热议问题