ReflectionClass::getTraitAliases()函數是PHP中的內置函數,用於返回用戶定義的類使用的特征別名數組。
用法:
array ReflectionClass::getTraitAliases( void )
參數:該函數不接受任何參數。
返回值:此函數返回用戶定義的類使用的特征別名的數組。
以下示例程序旨在說明PHP中的ReflectionClass::getTraitAliases()函數:
示例1:
<?php 
  
// Defining a trait class 
trait Company { 
    public function GeeksforGeeks() { 
    } 
} 
  
// Defining a user-defined class Department 
class Department{ 
  use Company { 
        Company::GeeksforGeeks as Portal; 
    } 
} 
  
// Using ReflectionClass over the 
// user-defined class Department 
$obj=new ReflectionClass('Department'); 
  
// Caling the getTraitAliases() function 
$A = $obj->getTraitAliases(); 
  
// Getting an array of the trait aliases 
var_dump($A);  
?>輸出:
array(1) {
  ["Portal"]=>
  string(22) "Company::GeeksforGeeks"
}
示例2:
<?php 
   
// Defining a user-defined class Department 
class Department{ 
} 
   
// Using ReflectionClass over the 
// user-defined class Department 
$obj=new ReflectionClass('Department'); 
   
// Calling the getTraitAliases() function and 
// getting an array of the trait aliases 
var_dump($obj->getTraitAliases());  
?>輸出:
array(0) {
}
參考: https://secure.php.net/manual/en/reflectionclass.gettraitaliases.php
相關用法
- PHP ReflectionClass isUserDefined()用法及代碼示例
- PHP ReflectionClass isIterateable()用法及代碼示例
- PHP ReflectionClass getMethod()用法及代碼示例
- PHP ReflectionClass getProperty()用法及代碼示例
- PHP ReflectionClass getProperties()用法及代碼示例
- PHP ReflectionClass getInterfaceNames()用法及代碼示例
- PHP ReflectionClass isTrait()用法及代碼示例
- PHP ReflectionClass getDefaultProperties()用法及代碼示例
- PHP ReflectionClass isSubclassOf()用法及代碼示例
- PHP ReflectionClass hasConstant()用法及代碼示例
- PHP ReflectionClass getStartLine()用法及代碼示例
- PHP ReflectionClass isAnonymous()用法及代碼示例
- PHP ReflectionClass isAbstract()用法及代碼示例
- PHP ReflectionClass implementsInterface()用法及代碼示例
- PHP ReflectionClass getConstant()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 PHP | ReflectionClass getTraitAliases() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
