top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between require_once and require in PHP?

0 votes
644 views
What is the difference between require_once and require in PHP?
posted Dec 23, 2017 by Jdk

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes

require()
The require() function is identical to include(), except that it handles errors differently. If an error occurs, the include() function generates a warning, but the script will continue execution. The require() generates a fatal error, and the script will stop.

require_once()
The require_once() statement is identical to require() except PHP will check if the file has already been included, and if so, not include (require) it again.

answer Dec 26, 2017 by Madhavi Latha
0 votes

The require statement has two variations, require and require_once.

The require/require_once statement is used to include file.

Require_once is ignored if the required file has already been added by any of the four include statements.
It has the following syntax:

<?php
require 'file_name';
?>

<?php
require_once 'file_name';
?>
answer Aug 14, 2019 by Siddhi Patel
...