我有一个文件(color.php)包含在我的index.php中。在包含的文件中,我定义了一些变量和函数。PHP全局变量修饰符不起作用
(color.php)
<?php
$colors = array(0xffffff, 0x000000, 0x000000, 0x808080);
function getColors() {
global $colors;
return $colors;
}
?>
下面是我的主文件(的index.php)。
<?php
require_once('color.php');
class Test {
function Test() {
var_dump(getColors()); // returns NULL
}
}
?>
为什么调用getColors()函数,它返回NULL,据说会返回一个颜色数组?我错过了什么吗?或者是否有需要在php.ini中的任何配置?任何帮助将非常感激。谢谢!