小编bla*_*tus的帖子

类名称中的PHP命名空间和全局变量问题

我不知道为什么我的HelperClass()下的全局$ error返回为空,我不知道为什么我可以验证$ class-> error确实填满了之前的数据.

在这种情况下,我不知道有关于命名空间的某些问题吗?请给我一些指示.

以下是一些相关的代码.

在主文件下

namespace Core;
$class = new ControllerClass();
$error = $class->error;
// verified that $error prints correctly here
include ViewFile.php;
Run Code Online (Sandbox Code Playgroud)

在ViewFile.php下

$helper = new HelperClass();
// __autoload function took care of the include
Run Code Online (Sandbox Code Playgroud)

在HelperClass下:

namespace Core\Skeleton;

class HelperClass {
public function __construct() {
global $error;
// $error != $class->error as defined earlier    
// $error is empty here
}
Run Code Online (Sandbox Code Playgroud)

php namespaces global-variables

3
推荐指数
1
解决办法
4616
查看次数

标签 统计

global-variables ×1

namespaces ×1

php ×1