difference between include and require

Discussion in 'PHP' started by bhuppi890109, Apr 22, 2011.

  1. #1
    hi friends ..i am beginner in php..
    my question is
    what is the difference between include and require..??

    i know one difference i.e include show the warning and continue the execution
    and require stop the execution and show the error
     
    bhuppi890109, Apr 22, 2011 IP
  2. Irfi0009

    Irfi0009 Banned

    Messages:
    17,584
    Likes Received:
    33
    Best Answers:
    1
    Trophy Points:
    48
    #2
    Here is answer of your question

    require() and include() are identical in every way except how they handle failure. include() produces a Warning while require() results in a Fatal Error. In other words, don’t hesitate to 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. Be sure to have an appropriate include_path setting as well.


    So that means, if you want to ensure that file1.php must be read before execute anything else, then you should use require.

    If you just want to load a ‘not that important’ template header then you can use include function.
     
    Irfi0009, Apr 22, 2011 IP