ReflectionClass::getParentClass()函数是PHP中的内置函数,用于返回指定的父类;如果不存在父类,则返回false。
用法:
ReflectionClass ReflectionClass::getParentClass ( void )
参数:该函数不接受任何参数。
返回值:此函数返回指定的父类;如果不存在父类,则返回false。
以下示例程序旨在说明PHP中的ReflectionClass::getParentClass()函数:
示例1:
<?php
// Defining a class named as College
class College {
// Defining a protected property
protected $College_Name = 'IIT Delhi';
}
// Defining a sub class Departments of the
// base class College
class Departments extends College {
public $Dept1 = 'CSE';
private $Dept2 = 'ECE';
public static $Dept3 = 'EE';
}
// Using ReflectionClass over sub class Departments
$ReflectionClass = new ReflectionClass('Departments');
// Getting the name of the parent class
var_dump($ReflectionClass->getParentClass());
?>
输出:
object(ReflectionClass)#2 (1) { ["name"]=> string(7) "College" }
示例2:
<?php
// Defining a class named as College
class College {
// Defining a protected property
protected $College_Name = 'IIT Delhi';
}
// Using ReflectionClass over the class College
$ReflectionClass = new ReflectionClass('College');
// Getting the name of the parent class
var_dump($ReflectionClass->getParentClass());
?>
输出:
bool(false)
参考: https://www.php.net/manual/en/reflectionclass.getparentclass.php
相关用法
- PHP ReflectionClass getInterfaceNames()用法及代码示例
- PHP ReflectionClass isIterateable()用法及代码示例
- PHP ReflectionClass inNamespace()用法及代码示例
- PHP ReflectionClass getMethod()用法及代码示例
- PHP ReflectionClass getProperty()用法及代码示例
- PHP ReflectionClass getProperties()用法及代码示例
- PHP ReflectionClass isUserDefined()用法及代码示例
- PHP ReflectionClass getDefaultProperties()用法及代码示例
- PHP ReflectionClass isTrait()用法及代码示例
- PHP ReflectionClass isSubclassOf()用法及代码示例
- PHP ReflectionClass hasConstant()用法及代码示例
- PHP ReflectionClass isAbstract()用法及代码示例
- PHP ReflectionClass isAnonymous()用法及代码示例
- PHP ReflectionClass getStartLine()用法及代码示例
- PHP ReflectionClass implementsInterface()用法及代码示例
注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 PHP | ReflectionClass getParentClass() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。