Los Frijoles Posted September 18, 2008 Share Posted September 18, 2008 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 More sharing options...
uniflare Posted September 18, 2008 Share Posted September 18, 2008 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. Link to comment https://forums.phpfreaks.com/topic/124808-solved-object-turns-into-non-object/#findComment-644742 Share on other sites More sharing options...
Los Frijoles Posted September 18, 2008 Author Share Posted September 18, 2008 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... Link to comment https://forums.phpfreaks.com/topic/124808-solved-object-turns-into-non-object/#findComment-644749 Share on other sites More sharing options...
uniflare Posted September 18, 2008 Share Posted September 18, 2008 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()); Link to comment https://forums.phpfreaks.com/topic/124808-solved-object-turns-into-non-object/#findComment-644753 Share on other sites More sharing options...
Los Frijoles Posted September 18, 2008 Author Share Posted September 18, 2008 It was a really obscure function reference inside of a different class which was causing the issue. It appears that I forgot a $this-> in another class file...I REALLY wish PHP had stack and call dumps in its error messages... Link to comment https://forums.phpfreaks.com/topic/124808-solved-object-turns-into-non-object/#findComment-644769 Share on other sites More sharing options...
uniflare Posted September 18, 2008 Share Posted September 18, 2008 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. Link to comment https://forums.phpfreaks.com/topic/124808-solved-object-turns-into-non-object/#findComment-644773 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.