I researched for a way to check if an object is an object (not a particular instance of a class) and i found is_object();
. Does is_object()
throw any exceptions? Is there a way to throw an exceptions with this language construct?
private function objectInjector($object) {
try {
is_object($object);
return strtolower(get_class($object));
} catch (Exception $ex) {
$this->ex = $ex->getMessage();
if (APP_DEBUG) {
d($ex->getTrace());
}
}
}
The function is_object() returns a bool and should be used in an if statement in order to correctly handle the result.
You can find more on the PHP documentation: http://php.net/manual/en/function.is-object.php
There is a why you need to throw an exception in that function? If not you can just add this code in your logic without delegate to objectInjector:
if (is_object($object)) {
//do stuff with your object
} else {
//do anything else, is not an object
}
The you can use a try/catch statement on top of your function/method to handle any other expection.
Bye!