Hi there, i'm not sure 100% how to phrase the question and explain what i'm trying to do, so bare with me.

Basically, i'd like to try and interupt a function call or class call and do some checks first. The best way I can think to do so is to call a function that does its checks and returns the function or class e.g:


PHP Code:
function getClass($className) {
     
//do stuff
     
return new $className;
}

$class getClass("className"); 
That works in its simplest format, but of course classes and functions have arguments sent to them and this poses a problem, as the possibilities for the different arguments are endless.

I thought there'd be an easy way around this using func_get_args. However I don't know how to then send the arguments to the function or class other than in an array. So the only solution i've been able to come up with is to just accept a single argument as an array and then use the list function, e.g:

PHP Code:
class className {
    public function 
__construct($args) {
        list(
$this->option1$this->option2$this->option3) = $args;
    }
}

function 
getClass() {
    
$args func_get_args();

    
//The class name should be the first paramater and we don't want to send it to the class.
    
$className array_shift($args);

    
//do stuff
    
return new $className($args);
}

$class getClass("className","someOption","anotherOption");