ReflectionClass::getProperty()函数是PHP中的内置函数,用于检查指定的属性是否存在。
用法:
bool ReflectionClass::hasProperty( string $name )
参数:该函数接受单个参数$name,该参数保存正在检查的属性的名称。
返回值:如果存在指定的属性,则此函数返回true,否则返回false。
以下示例程序旨在说明PHP中的ReflectionClass::hasProperty()函数:
程序1:
<?php 
  
// Using ReflectionClass  
$ReflectionClass = new ReflectionClass('ReflectionClass'); 
  
// Initializing a property name 
$a = 'name'; 
  
// Calling hasProperty() function over 
// the property name 
$Property = $ReflectionClass->hasProperty($a); 
  
// Getting the value true or false 
var_dump($Property); 
?>
输出:
bool(true)
程序2:
<?php 
   
// Defining a user-defined class Company 
class Company { 
    Public Function GeeksforGeeks() {} 
    Private Function GFG() {} 
} 
   
// Using ReflectionClass over the above  
// Company class 
$Class = new ReflectionClass('Company'); 
   
// Calling hasProperty() function 
$A = $Class->hasProperty($Class); 
   
// Getting the value either true or false 
var_dump($A); 
?>
输出:
bool(false)
参考: https://www.php.net/manual/en/reflectionclass.hasproperty.php
相关用法
- PHP ReflectionClass getReflectionConstant()用法及代码示例
- PHP ReflectionClass isFinal()用法及代码示例
- PHP ReflectionClass getTraits()用法及代码示例
- PHP ReflectionClass getInterfaces()用法及代码示例
- PHP ReflectionClass isInstance()用法及代码示例
- PHP ReflectionClass getTraitAliases()用法及代码示例
- PHP ReflectionClass getTraitNames()用法及代码示例
- PHP ReflectionClass hasMethod()用法及代码示例
- PHP ReflectionClass getExtensionName()用法及代码示例
- PHP ReflectionClass getProperties()用法及代码示例
- PHP ReflectionClass getProperty()用法及代码示例
- PHP ReflectionClass getStaticProperties()用法及代码示例
- PHP ReflectionClass __toString()用法及代码示例
- PHP ReflectionClass getFileName()用法及代码示例
- PHP ReflectionClass getDefaultProperties()用法及代码示例
注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 PHP | ReflectionClass hasProperty() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
