函数名称:ReflectionMethod::isProtected()
适用版本:PHP 5 >= 5.2.0, PHP 7
函数说明:ReflectionMethod::isProtected()
方法用于检查当前方法是否为受保护的。
用法示例:
<?php
class MyClass {
protected function myProtectedMethod() {
// some code here
}
}
$reflectionClass = new ReflectionClass('MyClass');
$reflectionMethod = $reflectionClass->getMethod('myProtectedMethod');
if ($reflectionMethod->isProtected()) {
echo "This method is protected.";
} else {
echo "This method is not protected.";
}
?>
在上面的示例中,我们首先定义了一个名为MyClass
的类,并在其中声明了一个受保护的方法myProtectedMethod()
。然后,我们使用ReflectionClass
类创建了一个反射类对象,并使用getMethod()
方法获取了myProtectedMethod()
方法的反射对象。
接下来,我们使用isProtected()
方法检查该方法是否为受保护的。如果是受保护的方法,则输出"This method is protected.";否则,输出"This method is not protected."。
请注意,为了使用ReflectionMethod
类,您需要启用Reflection扩展。