我有一个类似于这样的脚本:
傅.php
class Foo
{
function Foo() {
$Registry = array();
include 'bar.php';
$Registry['bar'] = new Bar();
}
}
酒吧.php
class Bar
{
function Bar() {
global $Registry;
print_r(var_dump($Registry));
}
}
但这返回:
array
'Registry' => &null
有没有人对为什么它不将Registry
变量标识为数组有任何建议?
你必须在全局和类之外创建$register
$Registry = array();
class Foo
{
function Foo() {
global $Registry;
include 'bar.php';
$Registry['bar'] = new Bar();
}
}
酒吧.php
class Bar
{
function Bar() {
global $Registry;
print_r(var_dump($Registry));
}
}
也许在
这两个函数中尝试全局。
因为
$Registry
不存在,所以Foo->Registry
存在,但这应该是从对象本身访问的。