note 94112 modified in function.method-exists by danbrown

From: Date: Fri, 16 Oct 2009 23:35:53 +0000
Subject: note 94112 modified in function.method-exists by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-161820@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: <?php // 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.. ?> --was-- 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.. http://php.net/manual/en/function.method-exists.php

« previous php.notes (#161820) next »