why use require_once
I know this sounds like a stupid question but why would you use require_once, why dont you just put the code in the same file?
because you can use the same code in different pages, so if you had to make a change to that code, you just change the file thats being included vs changing the same code in every page. You just include once, because other pages included might also include the same file, so if it's already been included, then the rest of the includes are ignored.
//this database.php include is ignored.
echo 'year 2008.';
You may also learn about both include and require do the same job, but if test.php is not available then require will stop the program by creating a fatal error but include will allow you to continue but it'll show a warning mesg!
require_once is typically used to require files which define classes and/or functions, as (1) you only need to define them once per script, and (2) you'll get a fatal error if you try to define the same class or function name more than once.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)