What is the operating mechanism of include and require in PHP?

Source: Internet
Author: User
When learning Zend, you can see the following code: {code ...} I also made some attempts: var_dump (require & #039; test. php & #039;) 1. if no return statement exists, the output is: {code ...} 2. if the return statement is used, enter the return data: {code ...} may I ask PHP... the following code is displayed during Zend learning:

$config = new Zend_Config(require 'config.php');

I also made some attempts:
Var_dump (require 'test. php ')
1. If there is no return statement, the output is:

int(1)

2. If the return statement is used, the input is the return data:

...

What are the require and include mechanisms of PHP?
PS: although the PHP source code has been downloaded, I cannot find a clue at the moment.

Update
One test. php output. php

// output.phpoutput(require 'test.php');// or output(include 'test.php');function output($test) {    var_dump($test);}

Scenario 1

// test.php 1return 123;
// output 1int(123)

Scenario 2

// test.php 2echo 123;
// output 2123int(1)

Case 3

// test.php 3echo 123;die;
// output 3123

Reply content:

The following code is displayed during Zend learning:

$config = new Zend_Config(require 'config.php');

I also made some attempts:
Var_dump (require 'test. php ')
1. If there is no return statement, the output is:

int(1)

2. If the return statement is used, the input is the return data:

...

What are the require and include mechanisms of PHP?
PS: although the PHP source code has been downloaded, I cannot find a clue at the moment.

Update
One test. php output. php

// output.phpoutput(require 'test.php');// or output(include 'test.php');function output($test) {    var_dump($test);}

Scenario 1

// test.php 1return 123;
// output 1int(123)

Scenario 2

// test.php 2echo 123;
// output 2123int(1)

Case 3

// test.php 3echo 123;die;
// output 3123

According to the official explanation provided by php, the difference between require and include is that a fatal error is thrown when require encounters an error, while include only throws warning.

Require () is identical to include () failed t upon failure it will also produce a fatal E_COMPILE_ERROR level error. in other words, it will halt the script whereas include () only emits a warning (E_WARNING) which allows the script to continue.
See the include () documentation for how this works.

Their principle is: parse the file to be included according to HTML, and replace the output content with the position of the include statement.

There is a Laruence article here for reference to http://www.laruence.com/2010/05/04/14...

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.