views:

33

answers:

4

Hi,

I am working on a Zend project and it has been well over 12 months since I touched Zend, I am getting an error on one of my functions, and I cannot work out why, I think it may be down to the site being originally built in an earlier version of PHP (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 is as follows,

get_class() expects parameter 1 to be object, array given in /server/app/lib/View.php on line 449

Any advice on the issue would be good.

+1  A: 

The get_class function requires the parameter to be an object. The error says that $mixedObject is an array.

It might help to check if $mixedObject is an object first:

$debugObject->className = is_object($mixedObject) ? get_class($mixedObject) : '';
Shiki
Not exactly bringing anything new to the table here.
Sam152
yeah, I was editing .. sorry
Shiki
+1  A: 

Have you already checked if "$mixedObject" is really an object? Because the error exactly says that it is not.

You could put a 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, the get_class returns a string so your check on that line would always be "true" (or false because you are negating it) and then empty string would be set. Try it like the example above.

TheCandyMan666
+1  A: 

It's expecting an object passed but you are setting it as an empty string and passing it after the question mark.

Evernoob
Thats not correct. The error occurs when get_class is called. At this point $mixedObject is whatever was passed to the function. The assignment of the empty string/return value of gettype would go into $debugObject->className.
TheCandyMan666
A: 

It looks like you pass as $mixedObject an array.

Check this var with is_object and then use gettype (if false) or get_class (if true).

hsz