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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。