Welcome to WebmasterWorld Guest from 54.198.222.129

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

What is the difference between include and require?

     
10:51 pm on Jun 18, 2007 (gmt 0)

5+ Year Member



I had a small site setup and functioning properly on my notebook running SuSE, Apache 2 and php 4.

the code went something like this

<html>
<head></head>
<body>
<?php require('header.php'); /?>

my content

<?php require('footer.php'); /?>

</bdoy>
</html>

When I put it up on my server, there was a parse error with the header file, but when I changed it to include instead of require, it worked fine. I thought the diff was how they handled errors?

11:05 pm on Jun 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's not actually working fine ... you're just not seeing the errors.

"include" says, "Go get that file and put it into the lineup HERE." It doesn't really care whether the file is error-free, or not, and will render the rest of the page if it encounters a "non-fatal" error in the included file.

"require" says, "Go get that file and put it into the lineup HERE, unless there is something wrong with it." An error in a required file will result in a fatal error. That stops everything right there. The file is "required" to be error free, because the rest of the page depends on it.

2:45 am on Jun 19, 2007 (gmt 0)

5+ Year Member



where do you start on finding where the error is? I never understood that.
2:49 am on Jun 19, 2007 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



Turn the error_reporting [us.php.net] and and go based on what error you are getting. It will usually specify a line in the code; this is where you want to start looking for errors.

We have a thread on troubleshooting [webmasterworld.com] code in our library. You might want to take a peek :)

 

Featured Threads

Hot Threads This Week

Hot Threads This Month