Asked 7 years ago
7 Jan 2017
Views 1631
noob

noob posted

difference between include , require and include_once , require_once in PHP ?

include , require , include_once , require_once all function do include file .

include("include.php");
include_once("include_once.php");
require("require.php");
require_once("require_once.php");

above code will include include.php , include_once.php , require.php , require_once.php

if all do include file so what is the difference between include , require , include_once , require_once ?
Phpworker

Phpworker
answered Nov 30 '-1 00:00

lets first check difference between include and require in PHP .
include function
-it include file ,
- if not found file which is need to include it will generate Warning , not generate critical error .
- means no stop of execution of the code if anything goes wrong


require function
- require function also include file
- but if require funciton does not found file which is need to include it will generate critical error means it stop execution of the code .
-means require function used when need file to include before next code run

include_once function will include file only once . so it avoid multi include file inclusion error. same as for require_once
Post Answer