I have a "best practice" question. I'm developing a OO MVC framework in PHP, and most of the classes interact easily - they are literally declared in the code and used. For instance:
// In class 'getDetails'
$db = new mysqli(.....);
$db->query(.....);
However, there are times when the class and function names are dynamically built. The actual class files are all created and located in the framework somewhere, but they are not all literally declared and used. It isn't until run time that the framework knows what class it needs to complete the request; so the class and function names are usually created and stored in variables. In the simplest case, the variables are used to create an object and run a function. Example:
$request = 'blog';
$action = 'view';
$class = new $request(); // Creates an blog object
$class->$action(); // Runs the blog function view
However, I have already run into a situation when trying to use variables to run static functions (here is the stack overflow question and answer) where the variables couldn't be used in the literal usage
( $request::$action() gives parse errors). I have seen in the PHP manual functions for interacting/using classes, functions, and objects, but have not had to deal with them before.
My question is what is the best way to handle and run classes and functions where the class and function names are created on the fly?