Differences between “include” and “require” in PHP

Differences between “include” and “require” in PHP, both include and require are php functions to include a file, and they act different depending on the results. If we are using include and is there any error in including file there is no problem with include, it moves to next step by showing an warning. And in require if it’s unable to require a file it will shows an fatal error message and it stops processing of remaining script.

include PHP function

The include statement includes and evaluates the specified file.

We can include php files in two types.

<?php
 include('file.php');
?>
<?php
include 'file.php';
?>

For more information on include php function at php.net.

require PHP functions

require is identical to include except upon failure it will also produce a fatal E_COMPILE_ERROR level error. In other words, it will halt the script whereas include only emits a warning (E_WARNING) which allows the script to continue.

<?php
 require('file.php');
?>
<?php
require 'file.php';
?>

For more information on require php function at php.net.

Vivek Vengala
 

Vivek Vengala is a Online Entrepreneur, Web Developer from Hyderabad India.

Click Here to Leave a Comment Below 0 comments

Leave a Reply:

x

Join My Facebook Group to Receive Coding Tutorial for Free

email-subsribe