【发布时间】:2010-02-18 15:52:18
【问题描述】:
如何从函数 a 中访问 函数 b?
这是我目前所拥有的,我收到了这个错误:PHP 致命错误:调用未定义的方法 a::b()
class test {
function a($x) {
switch($x)
{
case 'a'://Do something unrelated to class test2
break;
case 'b':
$this->b();
break;
}
}
}
class test2 extends test {
function b() {
echo 'This is what I need to access';
}
}
$example=new test();
$example2=new test2();
$example->a(b);
关于背景信息 - 函数 a 是通过 AJAX 发送的请求的开关。根据请求,它会调用一个函数来将记录添加到数据库、进行编辑等。
谢谢!
【问题讨论】:
-
很难写出一个容易理解的答案,因为你经常重复使用你的名字。我必须区分类测试和对象测试,而且你有一个名为“b”的神秘参数传递给函数“a”,同时还有一个名为“b”的函数。为了清楚起见,您应该在示例中使用更具描述性和唯一性的名称。
-
感谢您的快速解答。