note 94115 added to reflectionmethod.isprivate

From: Date: Fri, 16 Oct 2009 23:45:48 +0000
Subject: note 94115 added to reflectionmethod.isprivate
Groups: php.notes 
Request: Send a blank email to php-notes+get-161824@lists.php.net to get a copy of this message
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.. ---- Server IP: 89.190.194.18 Probable Submitter: 87.118.135.132 ---- Manual Page -- http://www.php.net/manual/en/reflectionmethod.isprivate.php Edit -- https://master.php.net/note/edit/94115 Del: integrated -- https://master.php.net/note/delete/94115/integrated Del: useless -- https://master.php.net/note/delete/94115/useless Del: bad code -- https://master.php.net/note/delete/94115/bad+code Del: spam -- https://master.php.net/note/delete/94115/spam Del: non-english -- https://master.php.net/note/delete/94115/non-english Del: in docs -- https://master.php.net/note/delete/94115/in+docs Del: other reasons-- https://master.php.net/note/delete/94115 Reject -- https://master.php.net/note/reject/94115 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161824) next »