They are not desirable, but it is great to use them as you have.
A few pointers: your code is vulnerable when an attacker could cross your directory with $_GET parameters such as ?class=../base . If this file exists, your call to file_exists() will return true , and your application will try to include it and create an instance as a class.
A safe scenario should be to assign white letters, numbers and underscores to these parameters (if you select words with underscores, i.e. .php ).
In addition, I prefer the syntax for using call_user_func and call_user_func_array . Using these functions in your code will look like this:
<?php $class_name = $_GET['class']; $method_name = $_GET['method']; $parameters = $_GET; unset($parameters['class'], $parameters['method']); // grabs any other $_GET parameters if (file_exists(BASE.'/controllers/'.$class_name.'.class.php')) { require BASE.'/controllers/'.$class_name.'.class.php'; $controller = new $class_name(); $response = call_user_func_array(array($controller, $action_name), $parameters); } else { header('HTTP/1.1 404 Not Found'); // ...and display an error message }
source share