ReflectionMethod::isProtected()

检查当前方法是否为受保护的

首字母:R

函数名称:ReflectionMethod::isProtected()

适用版本:PHP 5 >= 5.2.0, PHP 7

函数说明:ReflectionMethod::isProtected() 方法用于检查当前方法是否为受保护的。

用法示例:

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扩展。

同首字母函数