我有 PHP 代码
<?
class AParent {
function to_s() {
return $this->id;
}
}
class AChild {
public $id;
public $name;
function to_s() {
if(!empty($this->name)) {
$ret = $this->name;
} else {
$ret = /** call parent's method to_s() */
}
return $ret;
}
}
如何调用孩子重载的父母方法?:) 使用静态方法是可能的,但是如何使用非静态方法呢?
$a = new AChild();
$a->id = 1;
$a->name = 'Something';
echo $a; // Should echo "Something"
$b = new AChild();
$b->id = 2;
echo $b; // Should echo "2"