|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-06-19 09:16 UTC] felix dot devliegher at gmail dot com
[2008-06-19 21:18 UTC] johannes@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 21 22:00:01 2025 UTC |
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(); }