我有文件init.php
:如何從內部類的功能進入全球varibale
<?php
require_once 'config.php';
init::load();
?>
與config.php
:
<?php
$config = array('db'=>'abc','host'=>'xxx.xxx.xxx.xxxx',);
?>
一個類名something.php
:
<?php
class something{
public function __contruct(){}
public function doIt(){
global $config;
var_dump($config); // NULL
}
}
?>
莫非有人告訴我爲什麼它是空的? 在php.net中,他們告訴我,我可以訪問,但實際上並不是。 我試過但不知道。 我使用PHP 5.5.9。 在此先感謝。
你include'config.php'?只需包含並打印$ config –
從全局變爲手動! –