php - Jump to next includedfile after encountering an error in included file

181

I have a main PHP file that includes lots of separate files, with no relation between them.

<?php
include_once 'test/test1.php';
include_once 'test/test2.php';
include_once 'test/test3.php';
include_once 'test/test4.php';
include_once 'test/test5.php';
include_once 'test/test6.php';
include_once 'test/test7.php';
?>

But when I run this PHP file, maybe I will encounter errors in each file. I want to know which code is appropriate if the main file is faced with any error. It shouldn't stop working, but jump to the next file.
How can I do that?

508

Answer

Solution:

include_once will show a warning and continue execution to the next line, it will not exit out .

require_once will throw the error and exit out of the program.

People are also looking for solutions to the problem: php - Using container object from Included file

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.