|
-
Aug 2nd, 2007, 08:27 PM
#1
Thread Starter
Fanatic Member
Know if the class can be instantiated
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.
Last edited by nebulom; Aug 3rd, 2007 at 12:04 AM.
-
Aug 2nd, 2007, 11:13 PM
#2
Re: Know if the class can be instantiated
Code:
if (class_exists($class))
$controller = new $class;
else
// ...
-
Aug 3rd, 2007, 12:02 AM
#3
Thread Starter
Fanatic Member
Re: Know if the class can be instantiated
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|