古语题了,不得不再问一下include和require
老话题了,不得不再问一下include和require
手册上,include和require的区别只有一点,就是出错时产生的不同级别的错误。
但是,网上关于两者的区别远不止这一点,搞得我非常混乱
下面这些是我从网上摘抄的一些观点和疑问
--------------------------------------------------------------------------------------------------------
什么是“只要程序一执行就调用”?
<?php<br />//aa.php<br />echo 'aa';<br />require './bb.php';
我暂时这么想,因为也不懂什么编译之类的。请指点
require情况:执行aa.php时,把aa.php和bb.php一起编译,然后执行;
include情况:先把aa.php编译->执行,发现有include,然后把bb.php编译->执行bb.php,完成后返回继续执行aa.php下面的代码。
--------------------------------------------------------------------------------------------------------
这一点就非常搞不明白了。aa.php还是上面的那个代码,下面是bb.php,执行得好好的
<?php<br />//bb.php<br />if(true){<br /> echo 'bb';<br />}<br />return 'abc';
--------------------------------------------------------------------------------------------------------
文章中举了个例子并得出结论:
<?php<br />//aa.php<br />echo 'aa';<br />$i=1;<br />while($i<3){<br /> require './test' . $i . '.php';<br /> $i++;<br />}
但是,我测试却能将test1.php和test2.php都引入进来
<?php<br />echo 'test1';
<?php<br />echo 'test2';
输出:aatest1test2
--------------------------------------------------------------------------------------------------------------------------
<?php<br />//aa.php<br />if(false){<br /> require './bb.php';<br />}
是否是这样?如何能证明已经引入了bb.php?
------------------------------------------------------------------------------------------------------------------------
另外,还有一个关于报错的问题,手册上这么讲

<?php<br />//aa.php<br />include 'nofile.php';<br />//require 'nofile.php';
报错如下:
第一个warning是报什么样的错误?两个都是warning
第二个看像是在include_path里找不到而报的错?
------解决思路----------------------
所有的说明一最新的手册为准
网上关于include和require的描述,大多是基于php4的
到了php5时代,就只剩下 出错时产生的不同级别的错误 的区别了
------解决思路----------------------
IT知识的更新换代太快了,一切以官方手册为准,也可以研读一下PHP源码,看看是怎么处理的,那是最正确的。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.
