class test{ public $a="this is a"; public $b="this is b"; public function a() { return $this->a; } public function b($i) { return $this->a=$this->$i.$this->b; } }$db=new test(); echo "<span style='color:#red;'>this is a:</span>".$db->a(); echo "<br/>"; echo "<span style='color:#red;'>this is b:</span>".$db->b(0); echo "<br/>"; echo "<span style='color:#red;'>this is a+b:</span>".$db->b("a"); echo "<br/>"; $db=new test(); echo "<span style='color:#red;'>this is a-b:</span>".$db->a(); echo "<br/>"; echo "<span style='color:#red;'>this is b:</span>".$db->b(0); //这样是不是你要的要求
A+=B; //B附加到A
A(); //此时A执行时,会同时自动执行B
A-=B; //取消附加
A+=C; //同上上上
A(); //此时A执行时,会同时自动执行CPHP可有实现此功能的方法?
啊,不会吧?
就是像C#那样,把B函数句柄赋给A函数,然后当A函数执行时,也会自动执行B函数
这样明白点了吧?
function a(){echo "this is a";}
function b(){echo "this is b";}在function a(){echo "this is a";}不修改的情况下,可否让a()执行时,可否输出:
this is athis is b
A();B();//执行完A再B
A();C();//执行完A再C
感觉就跟这个一样效果,有什么特别需要吗?
class test{
public $a="this is a";
public $b="this is b";
public function a()
{
return $this->a;
}
public function b($i)
{
return $this->a=$this->$i.$this->b;
}
}$db=new test();
echo "<span style='color:#red;'>this is a:</span>".$db->a();
echo "<br/>";
echo "<span style='color:#red;'>this is b:</span>".$db->b(0);
echo "<br/>";
echo "<span style='color:#red;'>this is a+b:</span>".$db->b("a");
echo "<br/>";
$db=new test();
echo "<span style='color:#red;'>this is a-b:</span>".$db->a();
echo "<br/>";
echo "<span style='color:#red;'>this is b:</span>".$db->b(0);
//这样是不是你要的要求
http://blog.aisoyo.com/2009/03/php-%E2%80%9C%E4%BA%8B%E4%BB%B6%E7%9B%91%E5%90%AC%E2%80%9D-_/
//伪代码
function A($flag)(
if($flag) return $this->B();
return $this->C();
)
跟你想到的一样 总之不可能不修改B 又不是Perl 记得把帖子结了
————————————————————————————————
基于CSDN论坛提供的插件扩展功能,自己做了个签名档工具,分享给大家,欢迎技术交流 :)[/size]