有關PHP回呼函數的烏雲。
本人較菜,請問各位俠士,如何在PHP中達到EventStack的NotifyWatcher方法可以將取得的資料返還給welcome.php指定的回呼函數,我哪裡寫的不對啊 ???
出現的錯誤為:Fatal error: Function name must be a string in /home/latel/Workspace/new_zhebo/module/EventStack.php on line ××
/app/welcome.php
if (!defined("__IS_ROOT")) die("Access Denied");
global $EventStack;
//閉包函數(回調)
$fGetSettings = function($oSettingDaemon) {
//處理回調返回的系統設定資料模型
echo $oSettingDaemon;
};
//請求資料原型
$EventStack->addEvent(
"DATA_REQUEST",
serialize(array(
array(
"request" => "settingDaemon"
)
)),
$fGetSettings,
null
);
?>
/EventStack.php
//事件堆棧處理組件
/*數
*/
//已知的事件戳記
/*
*/
if (!defined("__IS_ROOT")) die("Access Denied");
class EventStack extends Init{
private $_aWatcherRegistry = array();//登入的觀察者列表
private $_aEventStack = array();//事件堆棧
private $_aCallbackRegistry = array();//登入的回呼函數
function __construct() {
}
function __destruct() {
//將關鍵資訊儲存至資料來源的Log表
//根據調試開關,決定是否輸出調試資訊至頁面
}
function __toString() {
}
##A##
public function addEvent($sStamp = "ISSUE_TRACK", $sValue, $fHandler = null, $mScope = null) {
/*sStamp: 此條訊息的戳記
*sValue: 序列化的數組
* fHandler(function): 匿名回呼函數
* mScope(mixed type): 回呼函數的上下文環境,
* null表示傳入的handler函數是一個全域函數,
* 字串類型表示傳入的handler函數是scope類的靜態函數,
* 物件類型表示傳入的scope是一個對象,handler函數是對象的一個方法
*/
$this->_aEventStack[] = array(
"stamp" => $sStamp,
"value" => $sValue,
"handler" => $fHandler,
"scope" => $mScope,
"timestamp" => time()
);
$iKey = sizeof($this->_aEventStack) - 1;
$this->notifyWatcher($iKey);
return $iKey;
}
public function addWatcher($oWatcher, $sWatchStamp) {
}
##C##
public function clearEventStack() {
//清空事件堆棧
}
##E##
public function exportEventStack() {
//輸出調試資訊
}
##G##
public function getStack($iStackId) {
//根據是否提供堆棧序號,返回堆棧列表或指定堆棧的內容
}
##N##
private function notifyWatcher($iKey) {
//推送事件至相應的觀察者
if (array_key_exists($this->_aEventStack[$iKey]["stamp"], $this->_aWatcherRegistry)) {
$mCallback = $this->_aWatcherRegistry[$this->_aEventStack[$iKey]["stamp"]](
$this->_aEventStack[$iKey]["stamp"],
$this->_aEventStack[$iKey]["value"],
$this->_aEventStack[$iKey]["handler"],
$this->_aEventStack[$iKey]["scope"]