ReflectionClass::isSubclassOf()函數是PHP中的內置函數,用於檢查是否有任何子類可用。
用法:
bool ReflectionClass::isSubclassOf( $class )
參數:此函數接受單個參數類,該參數類是要檢查的類名稱。
返回值:如果子類可用,則此函數返回TRUE,否則返回FALSE。
以下示例程序旨在說明PHP中的ReflectionClass::isSubclassOf()函數:
示例1:
<?php
// Initialising a user-defined superclass Company
class Company {
public function GeeksforGeeks() {}
}
// Creating a subclass Departments
class Departments extends Company {
public function HR_Department() {}
}
// Using ReflectionClass()
$subclass = new ReflectionClass('Departments');
// Calling the isSubclassOf() function
$Result = $subclass->isSubclassOf('Company');
// Getting the value true or false
var_dump($Result);
?>
輸出:
bool(true)
示例2:
<?php
// Initialising a user-defined class Departments
class Departments {
public function CSE() {}
}
// Using ReflectionClass() over the
// user-defined class Departments
$subclass = new ReflectionClass('Departments');
// Calling the isSubclassOf() function
$Result = $subclass->isSubclassOf('Departments');
// Getting the value true or false
var_dump($Result);
?>
輸出:
bool(false)
參考: https://www.php.net/manual/en/reflectionclass.issubclassof.php
相關用法
- PHP ReflectionClass isIterateable()用法及代碼示例
- PHP ReflectionClass isUserDefined()用法及代碼示例
- PHP ReflectionClass isTrait()用法及代碼示例
- PHP ReflectionClass getMethod()用法及代碼示例
- PHP ReflectionClass getProperty()用法及代碼示例
- PHP ReflectionClass getProperties()用法及代碼示例
- PHP ReflectionClass getInterfaceNames()用法及代碼示例
- PHP ReflectionClass getDefaultProperties()用法及代碼示例
- PHP ReflectionClass hasConstant()用法及代碼示例
- PHP ReflectionClass inNamespace()用法及代碼示例
- PHP ReflectionClass getStartLine()用法及代碼示例
- PHP ReflectionClass isAnonymous()用法及代碼示例
- PHP ReflectionClass isAbstract()用法及代碼示例
- PHP ReflectionClass implementsInterface()用法及代碼示例
- PHP ReflectionClass getConstant()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 PHP | ReflectionClass isSubclassOf() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。