您好,
这是一个有用的函数,您可以使用它来检查类的访问方法,例如它是公共的、私有的还是静态的,或者两者兼而有之。
如下所示
<?php
类 myClass {
private $private1;
static $static1;
public $public1;
public function publ() {
}
private function priv() {
}
private static function privstatic() {
}
public static function publstatic() {
}
static function mytest() {
}
}
function is_class_method($type="public", $method, $class) {
$refl = new ReflectionMethod($class, $method);
switch($type) {
case "static":
return $refl->isStatic();
break;
case "public":
return $refl->isPublic();
break;
case "private":
return $refl->isPrivate();
break;
}
}
var_dump(is_class_method("static", "privstatic", "myClass")); var_dump(is_class_method("private", "privstatic", "myClass")); var_dump(is_class_method("private", "publstatic", "myClass")); ?>