PDA

Click to See Complete Forum and Search --> : Know if the class can be instantiated


nebulom
Aug 2nd, 2007, 08:27 PM
I have a concatenation like

list($dummy, $class, $action) = split('/', $_SERVER['PATH_INFO']);
$class = ucfirst($class) . 'Controller';
$controller = new $class;

So if I'll pass /post I can have PostController but if the PostController doesn't exist, how do I know that so that I can't new $class coz it gives Cannot instantiate non-existent class: postcontroller?

Thanks in advance.

penagate
Aug 2nd, 2007, 11:13 PM
if (class_exists($class))
$controller = new $class;
else
// ...

nebulom
Aug 3rd, 2007, 12:02 AM
Thanks PG