Home  >  Article  >  Backend Development  >  问个子类对象直接调用基类内被重载的函数的有关问题

问个子类对象直接调用基类内被重载的函数的有关问题

WBOY
WBOYOriginal
2016-06-13 12:45:40891browse

问个子类对象直接调用基类内被重载的函数的问题?
/// 问题看如下代码
class A
{
function A()

$this->nNum = 1024;
}
function SelfClass()
{
echo "class A
";
}
}

class B extends A
{
function SelfClass()
{
echo "class B
";
}
}
?>

$obj = new B();
$obj->SelfClass(); // 调用B类的函数SelfClass()函数
/* 如何能使用对象obj的基类的SelfClass()函数?
C++下可以写类似的代码$obj->A::SelfClass(),那么PHP可以如何实现呢?*/
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn