您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

「求助」关于PHP回调函数的疑问

2025/1/8 20:33:03发布26次查看
本帖最后由 kericw 于 2013-11-01 15:37:40 编辑
php 回调 回调 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
addevent( data_request, serialize(array( array( request => settingdaemon ) )), $fgetsettings, null);?>
/eventstack.php
_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] ); //如果指定了回调函数,依据观察者返回的数据,做出具体的操作 if (isset($this->_aeventstack[$ikey][fhandler]) && !$mcallback) { $func = $this->_aeventstack[$ikey][fhandler]; $func($mcallback); } else { $func(null); } } } ##r## public function removewatcher($swatchstamp) { //移除指定的观察者 }}?>
回复讨论(解决方案) 只看到一次 $fgetsettings
只看到一次 $fgetsettings
版主,可以说的详细点么,我看了您的回答不是很懂。
我现在想这样,
welcome.php页通过eventstack->addevent的方法将回调函数注册到eventstack中,当eventstack获得相应的数据后将数据带入注册过的回调函数执行。
我语言表达能力不太好。
您的意思是global $fgetsettings么?
function name must be a string
函数名必须是一个字符串
你没有给出出错位置,我也不好猜测!
既然 $fgetsettings 是闭包,那么你总得在哪里用到他吧?
但你给出的代码片段中并没有
function name must be a string
函数名必须是一个字符串
你没有给出出错位置,我也不好猜测!
既然 $fgetsettings 是闭包,那么你总得在哪里用到他吧?
但你给出的代码片段中并没有
出错行在eventstack.php的第72行
闭包函数传递给了eventstack.php的37行
闭包当做参数,保存到该对象($eventstack)的私有数组属性 $_aeventstack中了
$eventstack取到数据后会在72行重新从尝试从数组中取出该函数,并将取得的数据作为参数传递给该函数
呵呵,看来我是缺乏提问的艺术。。
求帮忙啊,不然项目就搁在这里了。。。。。。
看来只能靠自己啊
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product