What is diffrence between inclue and require ?

Discussion in 'PHP' started by tomsign, Jul 24, 2010.

Thread Status:
Not open for further replies.
  1. #1
    Hi,,


    what is difference between include and require



    Thanks in advance:)
     
    tomsign, Jul 24, 2010 IP
  2. Zeh.

    Zeh. Peon

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    -php.net/include
     
    Zeh., Jul 24, 2010 IP
  3. arpit13

    arpit13 Well-Known Member

    Messages:
    294
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    128
    Digital Goods:
    1
    #3
    they don't have much difference just that if recquire fails it stops execution whereas include failure just show error message
     
    arpit13, Jul 24, 2010 IP
  4. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #4
    With include, even if the included file doesn't exist, it will still run the rest of the script. But with require, if the file doesn't exist, it will stop the whole script.
     
    Rainulf, Jul 24, 2010 IP
  5. qrpike

    qrpike Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    includes will continue on errors, require will stop the script if it does not find the file.

    In studies the most processor friendly is the require_once function. Always use that if possible
     
    qrpike, Jul 24, 2010 IP
  6. Andrew J

    Andrew J Peon

    Messages:
    32
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    On the contrary. require_once() is slower than require() since first it must check if the file that you want to require() has been required and then if it hasn't it requires the file.
     
    Andrew J, Jul 24, 2010 IP
  7. sandy_joy

    sandy_joy Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hi we use both, for importing file, that's we need & there is no huge difference between them, and the main difference is that, showing Result.
    suppose you have file "index.php"
    and you want to use code that's define in "index.php", then you just import that file, by avoiding re writing same code.
    <?php
    include('index.php');
    echo "Jai Shri Ram";
    ?>
    **********************************
    <?php
    require('index.php');
    echo "OM Sai Ram"
    ?>
    and suppose some error occurs, the include() function generates a warning, but the script will continue execution. The require() generates a fatal error, and the script will stop.
    and suppose you face some eror here then
     
    sandy_joy, Jul 27, 2010 IP
  8. kargaa

    kargaa Well-Known Member

    Messages:
    183
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #8
    as it says require , requires file if there is not file it wont work but include will give u error and contiunes.
     
    kargaa, Jul 28, 2010 IP
  9. Mohie

    Mohie Peon

    Messages:
    122
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #9
    basically both of them have the same "meaning" , and have the same effect if the file exist !!
    the only difference that with include file , if the file doesnt exist , the file.php will continue the execution and return back to u with some errors.
    but when using REQUIRE <-- from the name of this function , the required file should exist , if NOT it will generate a fatal error which will cause the die of ur code.
     
    Mohie, Jul 28, 2010 IP
  10. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #10
    Good explanation, except i would'nt call it meaning but functionality?

    Furthermore I don't see this thread going anywhere productive, as all the replies fulfill the OP's question, so this should be closed.
     
    danx10, Jul 28, 2010 IP
Thread Status:
Not open for further replies.