get_parent_class
(PHP 4, PHP 5, PHP 7)
get_parent_class - 检索对象或类的父类名称
描述
string get_parent_class ([ mixed $object ] )
检索对象或类的父类名称。
参数
object
被测对象或类名称。如果从对象的方法调用该参数,则该参数是可选的。
返回值
返回其object
实例或名称的类的父类的名称。
注意:如果对象没有父对象,或者给定的类不存在,
FALSE
则返回。
如果不带参数调用外部对象,则此函数返回FALSE
。
更新日志
Version | Description |
---|---|
5.1.0 | If called without parameter outside object, this function would have returned NULL with a warning, but now returns FALSE. |
例子
Example#1 使用get_parent_class()
<?php
class?dad?{
????function?dad()
????{
????//?implements?some?logic
????}
}
class?child?extends?dad?{
????function?child()
????{
????????echo?"I'm?"?,?get_parent_class($this)?,?"'s?son\n";
????}
}
class?child2?extends?dad?{
????function?child2()
????{
????????echo?"I'm?"?,?get_parent_class('child2')?,?"'s?son?too\n";
????}
}
$foo?=?new?child();
$bar?=?new?child2();
?>
上面的例子将输出:
I'm dad's son
I'm dad's son too
请参阅
- get_class() - 返回对象类的名称
- is_subclass_of() - 检查对象是否将此类作为其父项之一或实现它。
← get_object_vars
interface_exists →
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com