【发布时间】:2010-06-27 07:48:55
【问题描述】:
我的父类 c1 具有函数 hi()。类 c2 扩展了 c1 并包含通过方法 i() 的单例访问。在 c2 类中,我想创建与 c1 中同名的方法,我可以在静态范围内调用它,但在这个方法中,我想使用单例实例并从父类调用同名的方法。
class c1{
function hi(){
echo 'very '.$this->a;
}
}
class c2 extends c1{
private static $i;
public static function i() {
return (self::$i)?self::$i:(self::$i = new self);
}
public $a='cool';
function hi(){
self::i()->hi(); // here I want to call hi() from c1 but in instance scope
}
}
c2::hi(); //must echo: very cool
在实际示例中
c1 是 mysqli
c2 是我的自定义数据库类
并且 hi() 是 commit()
我希望能够调用db::commit(),所以我不需要写db::i()->commit();
编辑:PHP
【问题讨论】: