![]() |
Variable class names
I'm building a module system into something I'm coding right now, and in determining the best way to build a menu based off what modules/plugins are available I came across something I'm not sure if I can do or not.
Right now I have a very simple stopgap in that uses GET information to determine what module to load and the module takes care of the view and controller. The problem is I have the sidebar navigation menu hardcoded, and I want to make this dynamic. My first idea was to build a database of what modules were available (simply by running a check to see what files were in the module directory and running checks against them to determine that they fit the program), then after running through this list I would have a static displayMenu() method in each of these modules that could be called to build the menu. The problem I ran into is calling these methods dynamically, assuming that the super class has no idea what their names are. I wrote a quick three second test to see if I could assign their names to a variable and call them via that; PHP Code:
-m |
Before PHP 5.3.0 you can use:
call_user_func(array($var, 'displayMenu'));With PHP 5.3.0 and above you can use what you tried and it'll work fine. |
Much appreciated, I'm running 5.2.5 locally, if I recall correctly so is my server and I want to make this backwards compatible atleast to an extent, so I think I'll go with call_user_func().
In this case though wouldn't I want call_user_method()? I remember glossing over that in one of my reference manuals, IIRC it said they acted the same... I'll give it a go here. -m |
It would appear php.net isn't responding to me all day today... thankfully dreamweaver has a pocket reference built in, though it's hardly concise. So apparently if I wanted to use call_user_method() instead it would be like so;
PHP Code:
-m |
The call_user_method() function is deprecated as of PHP 4.1.0.
|
ca.php.net or us.php.net is available.
|
| All times are GMT. The time now is 07:40 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0