Jump to content

[SOLVED] Object turns into non-object???


Los Frijoles

Recommended Posts

Here is my code:

public static function restore($color)
{
$db = DbConnection::getDbConnection(); //line 71
$sql = $db->Prepare('select groupId, hexValue, colorName from Color where colorId = ? limit 1'); //line 72
try //line 73
{ //line 74
    echo is_a($color, "Color"); //line 75
    $rs = $db->execute($sql, array($color->getColorId())); //line 76
} //line 77
catch (exception $e)  //line 78
{ //line 79
    print_r($e); //line 80
} //line 81
...

 

The function is inside the class Color.

 

The purpose of the code is to retrieve certain values from a MySQL database based on an Id (colorId in this case). This problem has also cropped up in some of my other classes, but this is the least lengthy one and the easiest to show. Basically, what the problem is is that I get the following error when I try to execute the above code:

[Thu Sep 18 07:48:40 2008] [error] [client 10.25.100.99] PHP Fatal error:  Call to a member function getColorId() on a non-object in /srv/www/htdocs/scheduler/dataAccess/Color.class.php on line 76

 

However, the echo is_a... line outputs a 1 which means that it should be an instance of the Color class. This doesn't make sense...how can an object suddenly become a non-object???

Link to comment
https://forums.phpfreaks.com/topic/124808-solved-object-turns-into-non-object/
Share on other sites

i use objects just like you do, you must be missing something.

 

Use print_r($color), this should give you a list of all the variables and arrays etc stored in that object.

 

The function seems sound so at the very start of the pfunction put this print_r($color) and seewhat you get, my guess is your not passing an object in that variable when your calling this function somehow.

Replacing the echo is_a... with print_r returns the following:

Color Object
(
    [colorId:private] => 28
    [groupId:private] => 
    [hexValue:private] => 
    [colorName:private] => Dark Blue
    [id] => 45
)

 

Apparently it is being passed.

 

...the plot thickens...

hmm so it shud work, i see your dilemma.

 

ok try splitting the object calls onto sepearte lines:

 

$arrayvars = array($color->getColorId());
$rs = $db->execute($sql, $arrayvars); //line 76

 

if that dont work, try using the function in the print_r above, eg: print_r($color->getColorId());

I know what you mean, glad you found that little beggar :).

 

There are numerous debuggin applications out there, i think zend has one. Never used em though lol i believe there are a couple threads on here somewhere talking about debuggers.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.