Ethan
Ethan

Reputation: 5805

PHP function checking if you can create an object of a certain type?

It would take too long to explain why I need this, but I was wondering if there was a PHP function to check if a type of object was recognized. In other words, a function that would check if

$dog = new Dog();

would cause an error, because Dog didn't exist. Thanks for you help.

Upvotes: 0

Views: 86

Answers (2)

NawaMan
NawaMan

Reputation: 25687

See class_exists. I think it is what you want. OR you can just wrap it with a try catch block.

Hope this helps.

Upvotes: 1

nash
nash

Reputation: 2181

There is a function called class_exists

For further explanation, see the PHP manual page.

http://php.net/manual/en/function.class-exists.php

Upvotes: 4

Related Questions