The operating mechanism of PHP include and require is What?

  ios, question

In the process of learning Zend, I saw such code:

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

He also made some attempts:
var_dump(require ‘test.php’)
1. If there is no return statement, the output is:


2. If return statement, enter the data as return:


May I ask that PHP’s require and include mechanisms are What?
PS: Although I downloaded the source code of PHP, I couldn’t find a clue at the moment.

A Test for test.php output.php

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

Case 1

// test.php 1
return 123;
// output 1

Case 2

// test.php 2
echo 123;
// output 2

Case 3

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

According to the official php explanation, the difference between require and include is that require will throw a fatal error when it encounters an error, while include will only throw warning.

require() is identical to include() except 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 included file according to HTML, and then replace the position of the include statement with the output.

Here is an article by Laruence for reference. …