
get_parent_class() 函数返回对象或类的父类名
语法
get_parent_class ( $object );
定义和用法
它检索对象或类的父类名称。
如果 object 是对象,则返回对象实例 object 所属类的父类名。
如果 object 是字符串,则返回以此字符串为名的类的父类名。此功能是在 PHP 4.0.5 中增加的
参数
| 序号 | 参数及说明 |
|---|---|
| 1 | object(必需) 被测对象或类名。 |
返回值
它返回当前脚本中已声明类的名称的数组。
在线示例
以下是此函数的用法-
<?php
class f1 {
function f1() {
//实现一些逻辑
}
}
class child extends f1 {
function child() {
echo "I'm " , get_parent_class($this) , "'s son \n";
}
}
class child2 extends f1 {
function child2() {
echo "I'm " , get_parent_class('child2') , "'s son too \n";
}
}
$foo = new child();
$bar = new child2();
?>测试看看‹/›它将产生以下结果-
I'm f1's son I'm f1's son too