www.webdeveloper.com
Results 1 to 5 of 5

Thread: Difference between include_once and require_once

Hybrid View

  1. #1
    Join Date
    Oct 2013
    Posts
    2

    Difference between include_once and require_once

    Hello Friends,

    Can you please explain me difference between include_once() and require_once() with example?


    Bob,
    Web Developer
    QuickBooks Hosting Provider
    QuickBooks Hosting Services

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,175
    require[_once]() generates a fatal error if unable to load the specified file, while include[_once]() just generates a non-fatal error and the script keeps running.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Oct 2013
    Posts
    8
    - include() includes a file in memory no matter if it has already been loaded
    - include_once() includes a file in memory only if it has not been loaded already
    - require() includes a file in memory no matter if it has already been loaded. if the file cannot be loaded, the script is aborted
    - require_once() does the same as require(), but only if the file hasn't been included yet. if the file's already in memory, it has no effect.

  4. #4
    Join Date
    Sep 2013
    Posts
    5
    Include_once:includes and assesses the specified index and if the code from a document has recently been incorporated, it won't be incorporated once more

    Require_once: is indistinguishable to incorporate() aside from upon washout it will handle a deadly E_error level mistake. PHP will check if the record has as of recently been incorporated, and assuming this is the case, not incorporate (require) it once more.

  5. #5
    Join Date
    Sep 2013
    Posts
    221
    Require_once throws a fatal error if the file is not found, whereas include_once only show a warning and continue to load the rest of the page in php.
    If you don't want PHP to attempt to load the rest of your page without the database information , then use require_once.
    Include_once and require_once do the same thing, but only if the file was not already loaded.
    Require() includes and evaluates a specific file, while require_once() does that only if it has not been included before (on the same page).
    So, require_once() is recommended to use when you want to include a file where you have a lot of functions.
    Hope this helps.
    strad solutionswww.stradsolutions.com

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles