• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

OOP - Eigenschaft und Objekt vorhanden, dennoch Fehlermeldung

CGollhardt

Mitglied
Guten Abend,

ich sitze seit 2 Stunden vor einem Problem, kann den Fehler nicht finden. Und zwar habe ich ein befülltes Objekt, und bekomme trotzdem die Fehlermeldung

Notice: Trying to get property of non-object in...

Error Reporting ist bereits auf E_ALL.

Hier der besagte Code Ausschnitt:
PHP:
112:echo "<pre>";
113:print_r($tempGame);
114:echo "</pre>";
115:if ($tempGame -> achievements < $game -> gameAchievements) {
116:   $sql_Befehl = 'UPDATE `games` SET
117:   gamerscore = "' . $game -> gameGamerscore . '",
118:   achievements = "' . $game -> gameAchievements . '"
119:   WHERE id = "' . $tempGame -> id . '"';
120:   $objDB -> query ($sql_Befehl);
121:}
122:$GameID = $tempGame -> id;
Ausgabe:
Code:
Array
(
    [0] => stdClass Object
        (
            [id] => 48
            [name] => UNO
            [image32] => http://tiles.xbox.com/tiles/zK/X6/1mdsb2JgbA9ECgUAGwEfWSlQL2ljb24vMC84MDAwIAABAAAAAPnVpdM=.jpg
            [image64] => http://tiles.xbox.com/tiles/ow/vO/0Wdsb2JhbC9ECgUAGwEfWSlQL2ljb24vMC84MDAwAAAAAAAAAP7hC7w=.jpg
            [gamerscore] => 200
            [achievements] => 12
        )

)


Notice: Trying to get property of non-object in /hp/bp/aa/fl/www/clan/php/class/gamertag.class.php on line 115

Notice: Trying to get property of non-object in /hp/bp/aa/fl/www/clan/php/class/gamertag.class.php on line 119

Notice: Trying to get property of non-object in /hp/bp/aa/fl/www/clan/php/class/gamertag.class.php on line 122

Falls das nicht reicht hier nocheinmal die Methode:
PHP:
	function saveDataIntoDatabase ($UserID = 0, $OnlyUpdate = true) {
		if ($this -> userid == 0) {
			if ($UserID == 0) {
				return false;
			} else {
				$this -> userid = $UserID;
			}
		}
		if ($this -> goldMitglied) {
			$tempGoldmitglied = '1';
		} else {
			$tempGoldmitglied = '0';
		}
		if ($OnlyUpdate) {
			$sql_Befehl = 'UPDATE `gamertag` SET
				goldmitglied = "' . $tempGoldmitglied . '",
				gamerscore = "' . $this -> gamerscore . '",
				achievements = "' . $this -> achievements . '",
				maxgamerscore = "' . $this -> maxGamerscore . '",
				maxachievements = "' . $this -> maxAchievements . '",
				gamerpic = "' . $this -> gamerpic . '",
				profilurl = "' . $this -> profilUrl . '",
				lastupdatet = FROM_UNIXTIME(' . time () . ')
			WHERE userid = "' . $this -> userid . '"';
		} else {
			$sql_Befehl = 'INSERT INTO `gamertag` (
				`userid`,
				`goldmitglied`,
				`gamerscore`,
				`achievements`,
				`maxgamerscore`,
				`maxachievements`,
				`gamerpic`,
				`profilurl`,
				`lastupdatet`
			) VALUES (
				"' . $this -> userid . '",
				"' . $tempGoldmitglied . '",
				"' . $this -> gamerscore . '",
				"' . $this -> achievements . '",
				"' . $this -> maxGamerscore . '",
				"' . $this -> maxAchievements . '",
				"' . $this -> gamerpic . '",
				"' . $this -> profilUrl . '",
				FROM_UNIXTIME(' . time () . ')
			)';
		}
		$objDB = new db ();
		if ($objDB -> query ($sql_Befehl)) {
			foreach ($this -> games as $game) {
				$tempGame = $objDB -> select ('SELECT * FROM games WHERE name = "' . $game -> gameTitle . '"');
				if (count ($tempGame) < 1) {
					$sql_Befehl = 'INSERT INTO `games` (
						`name`,
						`image32`,
						`image64`,
						`gamerscore`,
						`achievements`
					) VALUES (
						"' . $game -> gameTitle . '",
						"' . $game -> gamePic32 . '",
						"' . $game -> gamePic64 . '",
						"' . $game -> gameGamerscore . '",
						"' . $game -> gameAchievements . '"
					)';
					$objDB -> query ($sql_Befehl);
					$GameID = mysql_insert_id ();
				} else {
					echo "<pre>";
					print_r($tempGame);
					echo "</pre>";
					if ($tempGame -> achievements < $game -> gameAchievements) {
						$sql_Befehl = 'UPDATE `games` SET
							gamerscore = "' . $game -> gameGamerscore . '",
							achievements = "' . $game -> gameAchievements . '"
						WHERE id = "' . $tempGame -> id . '"';
						$objDB -> query ($sql_Befehl);
					}
					$GameID = $tempGame -> id;
				}
				unset ($tempGame);
				if ($GameID > 0) {
					$tempProgress = $objDB -> select ('SELECT * FROM userprogress
						WHERE gameid = "' . $GameID . '" AND gamertagid = "' . $this -> userid . '"');
					if (count ($tempProgress) < 1) {
						$sql_Befehl = 'INSERT INTO `userprogress` (
							`gameid`,
							`gamertagid`,
							`gamerscore`,
							`achievements`,
							`lastplayed`
						) VALUES (
							"' . $GameID . '",
							"' . $this -> userid . '",
							"' . $game -> userGamerscore . '",
							"' . $game -> userAchievements . '",
							"' . $game -> lastPlayed . '"
						)';
						$objDB -> query ($sql_Befehl);
					} else {
						if ($tempProgress -> achievements < $game -> userAchievements) {
							$sql_Befehl = 'UPDATE `userprogress` SET
								gamerscore = "' . $game -> userGamerscore . '",
								achievements = "' . $game -> userAchievements . '"
							WHERE gameid = "' . $GameID . '" AND gamertagid = "' . $this -> userid . '"';
							$objDB -> query ($sql_Befehl);
						}
					}
					unset ($tempProgress);
				}
			}
			return true;			
		} else {
			return false;			
		}
	}

Ich weiß einfach nicht mehr, wo der Fehler liegen könnte...

Vielen Dank im voraus für eure Mühe.
 
Da der Platz nicht mehr gereicht hat (Sorry wegen Doppelpost), hier nocheinmal die komplette Klasse
PHP:
<?php
class gamertag {
	var $gamertag = '';
	var $valid = false;
	var $goldMitglied = false;
	var $gamerscore = 0;
	var $achievements = 0;
	var $maxGamerscore = 0;
	var $maxAchievements = 0;
	var $gamerpic = '';
	var $profilUrl = '';
	var $userid = 0;
	var $lastupdatet = 0;
	var $games = array ();
	function gamertag($gtag, $userID = 0) {
		$this -> gamertag = $gtag;
		$this -> userid = $userID;
		if ($this -> userid == 0) {
			$this -> getDataByXml($this -> gamertag);
		} else {
			$this -> getDataByDatabase ($this -> userid);
		}
	}
	function getDataByDatabase ($userID) {
		$objDB = new db ();
		if ($tempUserInfo = $objDB -> select ('SELECT * FROM gamertag WHERE userid = "' . $userID . '"', true)) {
			if ($tempUserInfo -> goldmitglied == '1') {
				$this -> goldMitglied = true;
			} else {
				$this -> goldMitglied = false;
			}
			$this -> gamerscore = $tempUserInfo -> gamerscore;
			$this -> achievements = $tempUserInfo -> achievements;
			$this -> maxGamerscore = $tempUserInfo -> maxgamerscore;
			$this -> maxAchievements = $tempUserInfo -> maxachievements;
			$this -> gamerpic = $tempUserInfo -> gamerpic;
			$this -> profilUrl = $tempUserInfo -> profilurl;
			$this -> lastupdatet = SQLDateTimeToTimestamp ($tempUserInfo -> lastupdatet);
		} else {
			$this -> valid = false;
		}
		unset ($tempUserInfo);
	}
	function saveDataIntoDatabase ($UserID = 0, $OnlyUpdate = true) {
		if ($this -> userid == 0) {
			if ($UserID == 0) {
				return false;
			} else {
				$this -> userid = $UserID;
			}
		}
		if ($this -> goldMitglied) {
			$tempGoldmitglied = '1';
		} else {
			$tempGoldmitglied = '0';
		}
		if ($OnlyUpdate) {
			$sql_Befehl = 'UPDATE `gamertag` SET
				goldmitglied = "' . $tempGoldmitglied . '",
				gamerscore = "' . $this -> gamerscore . '",
				achievements = "' . $this -> achievements . '",
				maxgamerscore = "' . $this -> maxGamerscore . '",
				maxachievements = "' . $this -> maxAchievements . '",
				gamerpic = "' . $this -> gamerpic . '",
				profilurl = "' . $this -> profilUrl . '",
				lastupdatet = FROM_UNIXTIME(' . time () . ')
			WHERE userid = "' . $this -> userid . '"';
		} else {
			$sql_Befehl = 'INSERT INTO `gamertag` (
				`userid`,
				`goldmitglied`,
				`gamerscore`,
				`achievements`,
				`maxgamerscore`,
				`maxachievements`,
				`gamerpic`,
				`profilurl`,
				`lastupdatet`
			) VALUES (
				"' . $this -> userid . '",
				"' . $tempGoldmitglied . '",
				"' . $this -> gamerscore . '",
				"' . $this -> achievements . '",
				"' . $this -> maxGamerscore . '",
				"' . $this -> maxAchievements . '",
				"' . $this -> gamerpic . '",
				"' . $this -> profilUrl . '",
				FROM_UNIXTIME(' . time () . ')
			)';
		}
		$objDB = new db ();
		if ($objDB -> query ($sql_Befehl)) {
			foreach ($this -> games as $game) {
				$tempGame = $objDB -> select ('SELECT * FROM games WHERE name = "' . $game -> gameTitle . '"');
				if (count ($tempGame) < 1) {
					$sql_Befehl = 'INSERT INTO `games` (
						`name`,
						`image32`,
						`image64`,
						`gamerscore`,
						`achievements`
					) VALUES (
						"' . $game -> gameTitle . '",
						"' . $game -> gamePic32 . '",
						"' . $game -> gamePic64 . '",
						"' . $game -> gameGamerscore . '",
						"' . $game -> gameAchievements . '"
					)';
					$objDB -> query ($sql_Befehl);
					$GameID = mysql_insert_id ();
				} else {
					echo "<pre>";
					print_r($tempGame);
					echo "</pre>";
					if ($tempGame -> achievements < $game -> gameAchievements) {
						$sql_Befehl = 'UPDATE `games` SET
							gamerscore = "' . $game -> gameGamerscore . '",
							achievements = "' . $game -> gameAchievements . '"
						WHERE id = "' . $tempGame -> id . '"';
						$objDB -> query ($sql_Befehl);
					}
					$GameID = $tempGame -> id;
				}
				unset ($tempGame);
				if ($GameID > 0) {
					$tempProgress = $objDB -> select ('SELECT * FROM userprogress
						WHERE gameid = "' . $GameID . '" AND gamertagid = "' . $this -> userid . '"');
					if (count ($tempProgress) < 1) {
						$sql_Befehl = 'INSERT INTO `userprogress` (
							`gameid`,
							`gamertagid`,
							`gamerscore`,
							`achievements`,
							`lastplayed`
						) VALUES (
							"' . $GameID . '",
							"' . $this -> userid . '",
							"' . $game -> userGamerscore . '",
							"' . $game -> userAchievements . '",
							"' . $game -> lastPlayed . '"
						)';
						$objDB -> query ($sql_Befehl);
					} else {
						if ($tempProgress -> achievements < $game -> userAchievements) {
							$sql_Befehl = 'UPDATE `userprogress` SET
								gamerscore = "' . $game -> userGamerscore . '",
								achievements = "' . $game -> userAchievements . '"
							WHERE gameid = "' . $GameID . '" AND gamertagid = "' . $this -> userid . '"';
							$objDB -> query ($sql_Befehl);
						}
					}
					unset ($tempProgress);
				}
			}
			return true;			
		} else {
			return false;			
		}
	}
	function getDataByXml ($gtag) {
		$xmlGamertag = simplexml_load_file('http://xboxapi.duncanmackenzie.net/gamertag.ashx?GamerTag=' . urlencode($gtag));
		if ($xmlGamertag -> PresenceInfo -> Valid == 'true' && strlen(str_replace(' ', '', $gtag)) > 0 && strlen($gtag) <= 25) {
			$this -> valid = true;
			$this -> gamerscore = $xmlGamertag -> GamerScore;
			$this -> gamerpic = $xmlGamertag -> TileUrl;
			if ($xmlGamertag -> AccountStatus = 'Gold') {
				$this -> goldMitglied = true;
			} else {
				$this -> goldMitglied = false;
			}
			$this -> profilUrl = $xmlGamertag -> ProfileUrl;
			$this -> achievements = 0;
			$this -> maxGamerscore = 0;
			$this -> maxAchievements = 0;
			for ($i = 0; $i < count ($xmlGamertag -> RecentGames -> XboxUserGameInfo); $i++) {
				$this -> games[$i] -> gameTitle = $xmlGamertag -> RecentGames -> XboxUserGameInfo[$i] -> Game -> Name;
				$this -> games[$i] -> gamePic32 = $xmlGamertag -> RecentGames -> XboxUserGameInfo[$i] -> Game -> Image32Url;
				$this -> games[$i] -> gamePic64 = $xmlGamertag -> RecentGames -> XboxUserGameInfo[$i] -> Game -> Image64Url;
				$this -> games[$i] -> gameGamerscore = $xmlGamertag -> RecentGames -> XboxUserGameInfo[$i] -> Game -> TotalGamerScore;
				$this -> games[$i] -> gameAchievements = $xmlGamertag -> RecentGames -> XboxUserGameInfo[$i] -> Game -> TotalAchievements;
				$this -> games[$i] -> userGamerscore = $xmlGamertag -> RecentGames -> XboxUserGameInfo[$i] -> GamerScore;
				$this -> games[$i] -> userAchievements = $xmlGamertag -> RecentGames -> XboxUserGameInfo[$i] -> Achievements;
				$this -> games[$i] -> lastPlayed = $xmlGamertag -> RecentGames -> XboxUserGameInfo[$i] -> LastPlayed;
				$this -> games[$i] -> lastPlayed = explode ('+', $this -> games[$i] -> lastPlayed);
				$this -> games[$i] -> lastPlayed = str_replace ('T',' ', $this -> games[$i] -> lastPlayed[0]);
				$this -> achievements += $this -> games[$i] -> userAchievements;
				$this -> maxGamerscore += $this -> games[$i] -> gameGamerscore;
				$this -> maxAchievements += $this -> games[$i] -> gameAchievements;
			}
		} else {
			$this -> valid = false;
		}
		unset ($xmlGamertag);
	}
	function CheckForUpdate ($ErzwungenesUpdate = false) {
		if ($this -> lastupdatet < time () - (60 * 60 * 12) || $ErzwungenesUpdate) {
			$this -> getDataByXml($this -> gamertag);
			$this -> saveDataIntoDatabase ($this -> userid, true);
		}
	}
}
?>
Die ausgabe könnt ihr euch hier über dem HTML Tag ansehen: German Gamer Society &bull; GGS Xbox 360 Clan » Home, es gibt folgende News

Ein Login ist erforderlich: Username "Testbenutzer" -- Passwort "test1234"
 
$tempGame ist ein Array mit einem Objekt drin, kein Objekt. Also quasi:

$tempGame = array(new stdClass());

Die Methode in Zeile 94

Code:
$tempGame = $objDB -> select ('SELECT * FROM games WHERE name = "' . $game -> gameTitle . '"');

gibt vermutlich immer ein Array zurück, auch wenn das ResultSet nur ein Element enthält.
 
$tempGame ist ein Array mit einem Objekt drin, kein Objekt. Also quasi:

$tempGame = array(new stdClass());

Die Methode in Zeile 94

Code:
$tempGame = $objDB -> select ('SELECT * FROM games WHERE name = "' . $game -> gameTitle . '"');
gibt vermutlich immer ein Array zurück, auch wenn das ResultSet nur ein Element enthält.

Vielen Dank, dass du dich mit meinem Code auseinandergesetzt hast. Genau das war das Problem. Habe der Select methode vergessen einen Parameter zu übergeben, das kein Array erstellt wird.

Also nochmals vielen Dank für deine Mühe.
 
Zurück
Oben