我正在寫一個配置文件解析器並在我的Config.php文件中有一個名爲getVals()的函數,但顯然當我在測試中調用它時會引發「未定義的函數」錯誤。當PHP存在未定義的函數時它存在
的config.php
<?php
require_once '../extlib/pear/Config/Lite.php';
class Config {
private $config;
function __construct($conf) {
$this->config = new Config_Lite();
echo "calling open...<br>";
$this->open($conf);
echo "open done...<br>";
}
function open($cfile) {
if (file_exists($cfile)) {
$this->config->read($cfile);
} else {
file_put_contents($cfile, "");
$this->open($cfile);
}
}
function getVals() {
return $this->config;
}
function setVals($group, $key, $value) {
$this->config->set($group, $key, $value);
}
function save() {
$this->config->save();
}
}
?>
在cfgtest.php
測試類
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
require_once '../util/Config.php';
$cfile = "../../test.cfg";
$cfg = new Config($cfile);
if (is_null($cfg)) {
echo "NULL";
} else {
echo $cfg.getVals();
}
?>
輸出
calling open...
open done...
Fatal error: Call to undefined function getVals() in cfgtest.php on line 13
我想知道爲什麼會出現未定義的函數錯誤時,有功能已經有了。