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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
