#45309 [NEW]: Need the ability to check if a method is public, private, or protected

From: Date: Thu, 19 Jun 2008 03:40:57 +0000
Subject: #45309 [NEW]: Need the ability to check if a method is public, private, or protected
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-125867@lists.php.net to get a copy of this message
From: php at suteki dot org Operating system: Linux (CentOS 5) PHP version: 5.2.6 PHP Bug Type: Feature/Change Request Bug description: Need the ability to check if a method is public, private, or protected Description: ------------ I can't seem to be able to find any php functions that would check if a method is public, private or protected before calling it. This would be used in a custom framework that loads classes as plugins. Right now if a method is private and the framework trys to call it and has no access, I get a fatal error (which I would like to avoid). I've worked around it for the time by doing some goofy naming in my class and putting some code into the function that dynamically calls the methods, but I think there should be a better way to handle things. Reproduce code: --------------- This is how I'm working around it right now... // Load the requested class. Then run the requested method. If the method is not available, run the default event. // Please name private methods with two leading underscores ( __ ) to prevent errors from occuring because PHP has no way of checking if an event is // private before it trys to run it.. $currentModule = url::get()->moduleID; $currentEvent = substr(url::get()->GET['event'], 0, 2) != '__' && url::get()->GET['event'] ? url::get()->GET['event'] : config::$defaultEvent; $$currentModule = new $currentModule; if (method_exists($$currentModule, $currentEvent)) { $$currentModule->$currentEvent(); } Expected result: ---------------- I would like to do something like this if possible... // Load the requested module. Then run the requested event. If the event is not available, run the default event. $currentModule = url::get()->moduleID; $currentEvent = url::get()->GET['event'] ? url::get()->GET['event'] : config::$defaultEvent; $$currentModule = new $currentModule; if (method_exists($$currentModule, $currentEvent) && method_encapsulation($$currentModule, $currentEvent) == 'public') { $$currentModule->$currentEvent(); } -- Edit bug report at http://bugs.php.net/?id=45309&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=45309&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=45309&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=45309&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=45309&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=45309&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=45309&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=45309&r=needscript Try newer version: http://bugs.php.net/fix.php?id=45309&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=45309&r=support Expected behavior: http://bugs.php.net/fix.php?id=45309&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=45309&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=45309&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=45309&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=45309&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=45309&r=dst IIS Stability: http://bugs.php.net/fix.php?id=45309&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=45309&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=45309&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=45309&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=45309&r=mysqlcfg

« previous php.bugs (#125867) next »