Difference between require() and require_once()?

Home / php-training-in-gurgaon / Difference between require() and require_once()?

The require() and require_once() functions perform same work. Both functions will include and evaluates the specific file while executing the code.

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 scenerio require() will throw fatal error and it will stop the script execution.

Example

<?php
echo “Hello”;
?>

test.php
<?php
require(‘echo.php’);
require_once(
‘echo.php’);
?>

test.php outputs: “Hello”.