Does this usage make sense? Will it cause any problems later?
function model($folder, $file)
{
global $db;
if (is_file(path . 'app/models/' . $folder . '/' . $file . '.php')) {
require_once(path . 'app/models/' . $folder . '/' . $file . '.php');
return new $file($db);
}
}
echo model('admin', 'common')->get();
2
Answers
That works fine since it’s possible to instantiate class by a variable containing that class name.
But I suggest, if you can, to use composer to auto-load classes. You can find tutorial about that.