views:

119

answers:

1

So I have a PHP class called router that takes the URL and explodes it to find the requested component, action and any given values. It then loads the responsible class, runs the action, etc, etc. I am now integrationg user access into the class via an user class.

For each component (which is a class), I have a static class array variable called 'perms' that holds each action as an index and a number as the minimum permission needed to run the action. Each component also has a static function to get the permission value for the passed action name.

The problem I am having is getting the static function to work correctly with the name of the class stored in a variable. In the router I use a variable to hold the name of the component.

$this->controller // cms, calendar ,etc

I then add 'Controller' to it to get the name of the class

$class = $this->controller.'Controller'; // cmsController, calendarController, etc

However, I am getting an error when I try to use it to access the static function

$minActionPerm = $class::getPerms( $this->action ); // No go, parse error

I get no error when I literally type in the class name, but this is not a real solution.

$minActionPerm = cmsController::getPerms( $this->action ); // Good, but literal

The variable also works when I create an object of the class to run the action.

$object = new $class();

I'm sure it is probably just a simple answer - such as variable use, but it's one I don't know as of right now.

+4  A: 

You need to use the call_user_func function.

Example:

call_user_func(array($class, 'getPerms'), $this->action);

If you are using PHP 5.2.3+ you can also do it this way:

call_user_func($class . '::getPerms', $this->action);
MitMaro