Explain include(),require(),include_once() and require_once() functions in PHP.


In this article, we will learn about useful and important functions in PHP for file inclusion. All these functions require, require_once, include and include_once are utilized to include the files in the php page but there is a slight distinction among them in terms of functionality.

Let's discuss these functions below with their functionality.

include() :

This function is used to include a file in a PHP page. If include() function is not able to find a specified file on location at that time it will throw a warning message however, it will not stop script execution.

require():

This function is utilized to add a file in a PHP page. In case of require() function if it can't locate a specified file at that time it will generate a fatal error and it will stop the content execution.

include_once():

This function is utilized to add a file only once at a time. If the code from a file has been already included then it will not be added again if we use include_once(). If it can't locate a specified file at that time it will generate a warning message but it will not stop the content execution.

require_once():

In case the code from a php file has been already included then it will not be included again if we use require_once(). It implies require_once() will add the file just once at a time. If it can't locate a specified file, at that time it will generate a fatal error but it will stop the content execution.

In this article we have learned how to implement functions like include(),require(),include_once(),require_once().

Updated on: 30-Jul-2019

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements