PHP issue with get_class
I am working on a Zend project and it has been over 12 months since I touched Zend, I get an error in one of my functions and I cannot figure out why, I think it might be up to the site originally built in an earlier PHP version (5.2) and I am now running 5.3.
The function looks like this:
public function addDebug($mixedObject, $title = "")
{
$debugObject = new stdClass();
$debugObject->title = $title;
$debugObject->type = gettype($mixedObject);
$debugObject->className = (!get_class($mixedObject)) ? "" : gettype($mixedObject);<-- Line error is complaining about -->
$debugObject->mixedObject = $mixedObject;
array_push($this->debugArr, $debugObject);
}
The error message looks like this:
get_class() expects parameter 1 to be object, array given in /server/app/lib/View.php on line 449
Any advice on this would be good.
a source to share
Have you already checked if the $ mixedObject is actually an object? Because the error says for sure that it is not.
You can check if the given $ mixedObject is an object or not:
if (is_object($mixedObject)) {
$debugObject->className = get_class($mixedObject);
} else {
$debugObject->className = gettype($mixedObject);
}
Edit: I also see some other error, get_class returns a string, so your check on that string will always be "true" (or false because you deny it) and then an empty string will be set. Try it like in the example above.
a source to share