【发布时间】:2017-05-20 07:57:11
【问题描述】:
我不明白为什么我的变量在多重包含之后没有设置。
在 header.php 中,我有一个变量 $a
public function defaultShow(){
include(dirname(__FILE__)."/../view/app/header.php");
include(dirname(__FILE__)."/../view/app/accueil.php");
include(dirname(__FILE__)."/../view/app/footer.php");
}
在 accueil.php 中设置了 $a。它的作品
但如果我的代码是
public function defaultShow(){
self::includeView("app/header");
self::includeView("app/accueil");
self::includeView("app/footer");
}
public static function includeView($view){
include dirname(__FILE__)."/../view/".$view.".php";
}
accueil.php 已加载,但此文件中的 $a 为空。
在 header.php 中设置的所有变量在 accueil.php 中都是空的
为什么?
感谢回复
纪尧姆
【问题讨论】:
-
全局 $a; $a = '最大';
标签: php include global-variables share