问一个关于php 对象方法和变量函数的问题 class A{ function Foo() { echo 'In foo...' }}$test = new A();function Bar($what){ $what();}提问,设置怎样的参数才能让Bar调用$test的Foo方法。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 把这个作为参数吗?楼主是问怎么把A::Foo作为参数传进Bar,让Bar来调用Foo 这样就可以了 参数可以在后面加call_user_func(array('A','Foo'), 参数 ..) 3楼是错的..用1楼的方法,那就不要写那个Bar函数了..直接call_user_func用这个函数就得了..这样的话,new也不就不用要喽 class A{ function Foo() { echo 'In foo...'; }}$test = new A();Bar($test,'Foo');function Bar($who,$what){ $who->$what();} class A{ function Foo() { echo 'In foo...'; }}$test = new A();function Bar($what){ $GLOBALS['test']->$what();}bar('foo'); <?phpclass A{ function Foo() { echo 'In foo...'; }}function Bar($a){ return $a->Foo();}$a=&new A();Bar($a);?> 请教如何获取PHP页面中靠查询数据库后输出一个记录的表格中记录的状态? 关于smarty模版的问题 数组和插入数据库的问题。急! PHP mysqli mysql 模块改写 求解一个问题 其他页面中获得一个循环中当前进度的好办法 求教~ 一个函数实在是写不出来。。 愁死我了,大家快来帮助我,在线等待,快!快!快!快!快!快!快! 高手请进,得分啊~``` 这是什么原因? html中嵌入php播放器? Facebook 将重写 PHP 运行环境
楼主是问怎么把A::Foo作为参数传进Bar,让Bar来调用Foo
这样就可以了 参数可以在后面加call_user_func(array('A','Foo'), 参数 ..)
用1楼的方法,那就不要写那个Bar函数了..直接call_user_func用这个函数就得了..
这样的话,new也不就不用要喽
{
function Foo()
{
echo 'In foo...';
}
}
$test = new A();
Bar($test,'Foo');
function Bar($who,$what)
{
$who->$what();
}
{
function Foo()
{
echo 'In foo...';
}
}
$test = new A();
function Bar($what)
{
$GLOBALS['test']->$what();
}bar('foo');
class A
{
function Foo()
{
echo 'In foo...';
}
}
function Bar($a)
{
return $a->Foo();
}
$a=&new A();
Bar($a);
?>