note 94112 added to function.method-exists

From: Date: Fri, 16 Oct 2009 23:30:51 +0000
Subject: note 94112 added to function.method-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-161819@lists.php.net to get a copy of this message
Hi, Here is a useful function that you can use to check classes methods access e.g whether it is public, private or static or both.. here it goes: // Example class 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: 69.147.83.197 Probable Submitter: 87.118.135.132 ---- Manual Page -- http://www.php.net/manual/en/function.method-exists.php Edit -- https://master.php.net/note/edit/94112 Del: integrated -- https://master.php.net/note/delete/94112/integrated Del: useless -- https://master.php.net/note/delete/94112/useless Del: bad code -- https://master.php.net/note/delete/94112/bad+code Del: spam -- https://master.php.net/note/delete/94112/spam Del: non-english -- https://master.php.net/note/delete/94112/non-english Del: in docs -- https://master.php.net/note/delete/94112/in+docs Del: other reasons-- https://master.php.net/note/delete/94112 Reject -- https://master.php.net/note/reject/94112 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161819) next »