Difference require_once & include_once

Discussion in 'PHP' started by coolguy123, Mar 11, 2007.

  1. #1
    As far as my understanding goes, I think include_once and require_once are identical in PHP 5, but I am not 100% sure as the php5 manual does not clearly point this out! I would like to know whether I am correct and if not, then what should be used for what?
     
    coolguy123, Mar 11, 2007 IP
  2. Robert Plank

    Robert Plank Peon

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    When you INCLUDE, and the file is missing or will not open, PHP gives a WARNING (complains about it but the script continues running).

    When you REQUIRE, and the file is missing or will not open, PHP gives an error (craps out and stops the script right there).

    If you include (or require)_once with a file, then try to require_once or include_once again, it will ignore it the 2nd time.
     
    Robert Plank, Mar 11, 2007 IP
  3. chuckd1356

    chuckd1356 Active Member

    Messages:
    770
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    70
    #3
    require_once() is best for DB files and other such stuff. You need it for it to run, and if your security logic isn't good, and you're DB file craps out you may run into problems.
     
    chuckd1356, Mar 11, 2007 IP