Difference between require and include in php

Source: Internet
Author: User
Include () or require () functions. you can insert the content of a file into the file before the server executes the php file. apart from the different ways in which they handle errors, these two functions are the same in other aspects. the include () function generates a warning.

Include () or require () functions, you can insert the content of a file into the file before the server executes the PHP file, in addition to the way they handle errors, these two functions are the same in other aspects.

Include () or require () functions, you can insert the content of a file into the file before the server executes the php file, in addition to the way they handle errors, these two functions are the same in other aspects. the include () function generates a warning (but the script continues to execute), and The require () function generates a fatal error (fatal error) (The execution will be stopped when an error occurs ).

  1.  
  2.  
  3.  
  4. Welcome to my home page
  5. Some text

     
  6.  
  7.  

Three Files: "default. php", "about. php", and "contact. php" all reference the "menu. php" file. this is the code in "default. php:

  1.  
  2. Welcome to my home page
  3. Some text

     
  4.  
  5.  

Require () function

The require () function is the same as include (), but the difference is that it handles errors.

The include () function generates a warning (but the script continues to execute), and The require () function generates a fatal error (the execution will be stopped when an error occurs ).

If an error occurs when you reference a file through include (), an error message similar to the following is returned:

  1.  
  2.  
  3. Include ("wrongfile. php ");
  4. Echo "hello world! ";
  5. ?>
  6.  
  7.  

Error message:

Warning: include (wrongfile. php) [function. include]: failed to open stream: no such file or directory in c: homewebsitetest. php on line 5 warning: include () [function. include]: failed opening 'wrongfile. php 'for declaration (include_path = '.; c: php5pear ') in c: homewebsitetest. php on line 5 hello world!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.