Home  >  Article  >  Backend Development  >  求php中的include()与自定义函数的优先级,该怎么解决

求php中的include()与自定义函数的优先级,该怎么解决

WBOY
WBOYOriginal
2016-06-13 12:53:48946browse

求php中的include()与自定义函数的优先级
新手,从asp转php勿怪!
有文件
a.php
b.php

b.php代码
===========================
function test(){echo "test";}
===========================

a.php
使用代码(正常代码)
===========================
include("b.php");
test();
===========================

使用代码(错误代码)
===========================
test();
include("b.php");
===========================


何解?
是不是include本身就属于函数
所以不存在函数内部的函数预防编译问题

include php asp function
------解决方案--------------------
include相当于把b.php文件中的函数放入到a.php

在还没有include之前就调用b.php文件中的函数,当然会出错
------解决方案--------------------
本帖最后由 xuzuning 于 2013-02-17 20:44:08 编辑 先声明,后使用
这是普遍的原则
------解决方案--------------------
楼上两位已经解释了原因。补充一点:
include、include_once、require、require_once都是语言结构而非函数。
------解决方案--------------------
对于php中函数的理解有没有什么比较好的方法,看了上面的回答之后总是感觉自己的理解似是而非的
------解决方案--------------------
引用:
对于php中函数的理解有没有什么比较好的方法,看了上面的回答之后总是感觉自己的理解似是而非的

多看看,多练练,慢慢加深记忆。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn