当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP ReflectionMethod isProtected()用法及代码示例


ReflectionMethod::isProtected()函数是PHP中的内置函数,如果指定的方法受保护,则用于返回TRUE,否则返回FALSE。

用法:

bool ReflectionMethod::isProtected ( void )

参数:该函数不接受任何参数。


返回值:如果指定的方法受保护,则此函数返回TRUE,否则返回FALSE。

以下示例程序旨在说明PHP中的ReflectionMethod::isProtected()函数:

程序1:

<?php 
  
// Initializing a user-defined class 
class Company { 
    protected function GFG() {} 
} 
  
// Using ReflectionMethod() over the class Company 
$A = new ReflectionMethod('Company', 'GFG'); 
  
// Calling the isProtected() function 
$B = $A->isProtected(); 
  
// Getting the value TRUE if the specified 
// method is protected, otherwise FALSE. 
var_dump($B); 
?>
输出:
bool(true)

程序2:

<?php 
   
// Initializing some user-defined classes 
class Department1 { 
   
    public function hr($name) { 
        return 'HR' . $name; 
    } 
} 
class Department2 { 
    protected function Coding() {} 
} 
  
class Department3 { 
     function marketing(){} 
} 
  
// Using ReflectionMethod() over the above classes 
$A = new ReflectionMethod('Department1', 'hR'); 
$B = new ReflectionMethod('Department2', 'Coding'); 
$C = new ReflectionMethod('Department3', 'marketing'); 
   
// Calling the isProtected() function and  
// getting the value TRUE if the specified 
// method is protected, otherwise FALSE. 
var_dump($A->isProtected()); 
var_dump($B->isProtected()); 
var_dump($C->isProtected()); 
?>

输出:

bool(false)
bool(true)
bool(false)

参考: https://www.php.net/manual/en/reflectionmethod.isprotected.php



相关用法


注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 PHP | ReflectionMethod isProtected() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。