Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Apr 2005
    Location
    Lahore, Pakistan
    Posts
    150
    Thanks
    2
    Thanked 0 Times in 0 Posts

    difference between include and Reuqire_once

    Can anyone explain, that what is the difference between "Include" and "require_once"

    plz require

    Eshban

  • #2
    Regular Coder
    Join Date
    Oct 2004
    Posts
    256
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The difference is in the level of error that will be returned if the file cannot be included/required.

    Like include() and require(), include_once() returns a warning and require_once() returns a fatal error.

    http://uk.php.net/manual/en/function.include.php

  • #3
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Also, I believe that with require_once, PHP will not require the same file twice (which will often lead to errors) eg, the code:

    require('functions.php');
    require('functions.php');

    will cause errors, becuase the first require loads the functions, and then the second file trys to re-declare them. using require_once in place of require will stop this from happening.

    Like Sayonara said, there are different levels of warning for include & include_once, and require & require_once

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    As with the *_once section for the functions, the difference this creates is that it will not include code already presented to it. So if you have a value that you would like to allow overwriting by another variable within an include, use include instead of include_once.


  •  

    Posting Permissions

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