note 94115 deleted from reflectionmethod.isprivate by danbrown
| From: | danbrown@php.net | Date: | Fri, 16 Oct 2009 23:47:29 +0000 |
| Subject: | note 94115 deleted from reflectionmethod.isprivate by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-161825@lists.php.net to get a copy of this message | ||
Note Submitter: admin ( at ) djokodonev dot com
----
Hi,
Here is a very good example for the usage of the Reflection class that php has..
The function below is something that you can use the check the type of a certain method of a
class... I use this to call different methods and combined with method exists etc... will allow you
controlled remote class methods calling...
class myClass {
private $private1;
static $static1;
public $public1;
public function publ() {
}
private function priv() {
}
private static function privstatic() {
}
public static function publstatic() {
}
static function mytest() {
}
}
// The function uses the reflection class that is built into PHP!!!
// The purpose is to determine the type of a certain method that exi
function is_class_method($type="public", $method, $class) {
// $type = mb_strtolower($type);
$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")); // true
- the method is private and also static..
var_dump(is_class_method("private", "privstatic", "myClass")); // true
- the method is private and also static..
var_dump(is_class_method("private", "publstatic", "myClass")); //
False the methos is public and also static not private
// you get the idea.. I hope this helps someone..