ID:               45309
 Comment by:       felix dot devliegher at gmail dot com
 Reported By:      php at suteki dot org
 Status:           Open
 Bug Type:         Feature/Change Request
 Operating System: Linux (CentOS 5)
 PHP Version:      5.2.6
 New Comment:

Have a look at SPL Reflection (http://be.php.net/reflection).
All functionality for getting a method's visibility is in there.


Previous Comments:
------------------------------------------------------------------------

[2008-06-19 03:40:56] php at suteki dot org

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 this bug report at http://bugs.php.net/?id=45309&edit=1

Reply via email to