IT Community - Software Programming, Web Development and Technical Support

What is the difference between require_once(), require(), include()?

This is a discussion on What is the difference between require_once(), require(), include()? within the PHP Programming forums, part of the Web Development category; Hi friends, Can any one expalin What is difference between require_once(), require(), include().Becouse above three function usely use to ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 07-25-2007, 09:33 AM
devarajan.v devarajan.v is offline
D-Web Master
 
Join Date: May 2007
Posts: 382
devarajan.v is on a distinguished road
Question What is the difference between require_once(), require(), include()?

Hi friends,

Can any one expalin What is difference between require_once(), require(), include().Becouse above three function usely use to call a file in another file?

Thanks
devarajan.V
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-26-2007, 10:28 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Default Re: What is the difference between require_once(), require(), include()?

include() will always include the file every time it’s called even if it’s the same file

while include_once() will only include the file once.

include() produces a Warning while require() results in a Fatal Error. In other words, use require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless

The require_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the require() statement, with the only difference being that if the code from a file has already been included, it will not be included again
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-30-2007, 05:57 AM
saravanan saravanan is offline
D-Web Sr.Programmer
 
Join Date: Jul 2007
Posts: 181
saravanan is on a distinguished road
Thumbs up Re: What is the difference between require_once(), require(), include()?

The difference between include() and include_once()
---------------------------------------------------

The only differnece between the two is that include() will always include the file every time it’s called, even if it’s the same file, while include_once() will only include the file once.
example
-------
//Included
include(‘the_file.php’);
//Included again, no point to this
include(‘the_file.php’);
//Included for the first time
include_once(‘the_file.php’);
//Not included again
include_once(‘the_file.php’);

difference between Require_once and include_once
-------------------------------------------------

The require() statement includes and evaluates the specific file.

The require_once() statement includes and evaluates the specified file during the execution of the script.


difference between include and require
-------------------------------------

The include() and require() statements includes and evaluate the specified file.
The two constructs are identical in every way except how they handle failure. include() produces a Warning while require() results in a Fatal Error.
Use require() if you want a missing file to halt processing of the page.

difference between include_once() and require_once()
---------------------------------------------------

include_once() should be used in cases where the same file might be included and evaluated more than once during a particular execution of a script, and you want to be sure that it is included exactly once to avoid problems with function redefinitions, variable value reassignments, etc.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/php-programming/2799-what-difference-between-require_once-require-include.html
Posted By For Type Date
What is the difference between require_once(), require(), include()? | Web Hosting This thread Refback 01-26-2008 12:20 PM

Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the difference between require, include and include_once? amansundar PHP Programming 3 11-28-2007 09:47 PM
Difference between#include< >and#include" " vigneshgets C and C++ Programming 1 08-01-2007 11:41 PM
Explain the difference between use and require. vadivelanvaidyanathan Perl 1 07-30-2007 07:39 AM
require_once(), require(), include() sivakumar PHP Programming 1 07-16-2007 07:39 AM
PHP: include &amp; require, what is different? montyauto PHP Programming 2 06-30-2007 01:17 AM


All times are GMT -7. The time now is 07:00 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0