...Beauty, cleaning, DIY tips and more - free to join!
   Login   Contact us   Site map   Puzzle Club   Ask a question    Newsletter

How To Require A File In PHP

Computing : Learning PHP

We know that to include a file in PHP that is optional but not fatal we use:
include ("myfile.php");

However there are occasions where we want the script to terminate if the file cannot be found.

For instance if it contains functions that are needed for the page and script to run correctly we will want to REQUIRE that file not just include it. Thus we use:

require ("myfile.php");

Now if the file cannot be found it will be a fatal error and script execution will terminate rather than with include where we just get a script error; depending on error_reporting levels.


By: Stephen

Share on Facebook: On Twitter: TwitterTweet this!

  Reply to How To Require A File In PHP

  Receive Our Newsletter




Questions about learn PHP:

Ask question

More Articles:
Newsletter formats and pros and cons
How to Correct System Hang at Startup
How to Turn Off Automatic Updates