从空值创建默认对象(stdClass?)

Creating default object from empty value ( stdClass? )

脚本 运行 很好,但只有当我取出用户组时,它才会说:

SteamUser.php (132): Creating default object from empty value

    function getProfileData() {

    //Set Base URL for the query:
    if(empty($this->vanityURL)) {
        $base = "http://steamcommunity.com/profiles/{$this->userID}/?xml=1";
    } else {
        $base = "http://steamcommunity.com/id/{$this->vanityURL}/?xml=1";
    }

    try {
        $content = SteamUtility::fetchURL($base);
        if ($content) {
            $parsedData = new SimpleXMLElement($content);
        } else {
            return null;
        }
    } catch (Exception $e) {
        //echo "Whoops! Something went wrong!\n\nException Info:\n" . $e . "\n\n";
        return null;
    }

    if(!empty($parsedData)) {   
        $this->steamID64 = (string)$parsedData->steamID64;
        $this->steamID = (string)$parsedData->steamID;
        $this->stateMessage = (string)$parsedData->stateMessage;
        $this->visibilityState = (int)$parsedData->visibilityState;
        $this->privacyState = (string)$parsedData->privacyState;

        $this->avatarIcon = (string)$parsedData->avatarIcon;
        $this->avatarMedium = (string)$parsedData->avatarMedium;
        $this->avatarFull = (string)$parsedData->avatarFull;

        $this->vacBanned = (int)$parsedData->vacBanned;
        $this->tradeBanState = (string)$parsedData->tradeBanState;
        $this->isLimitedAccount = (string)$parsedData->isLimitedAccount;

        $this->onlineState = (string)$parsedData->onlineState;
        $this->inGameServerIP = (string)$parsedData->inGameServerIP;

        //If their account is public, get that info:
        if($this->privacyState == "public") {
            $this->customURL = (string)$parsedData->customURL;
            $this->memberSince = (string)$parsedData->memberSince;

            $this->steamRating = (float)$parsedData->steamRating;
            $this->hoursPlayed2Wk = (float)$parsedData->hoursPlayed2Wk;

            $this->headline = (string)$parsedData->headline;
            $this->location = (string)$parsedData->location;
            $this->realname = (string)$parsedData->realname;
            $this->summary = (string)$parsedData->summary;
        }

        //If they're in a game, grab that info:
        if($this->onlineState == "in-game") {
            $this->inGameInfo = array();
            $this->inGameInfo["gameName"] = (string)$parsedData->inGameInfo->gameName;
            $this->inGameInfo["gameLink"] = (string)$parsedData->inGameInfo->gameLink;
            $this->inGameInfo["gameIcon"] = (string)$parsedData->inGameInfo->gameIcon;
            $this->inGameInfo["gameLogo"] = (string)$parsedData->inGameInfo->gameLogo;
            $this->inGameInfo["gameLogoSmall"] = (string)$parsedData->inGameInfo->gameLogoSmall;
        } 

        //Any weblinks listed in their profile:
        if(!empty($parsedData->weblinks)) {
            $this->weblinks = array();

            $i = 0;
            foreach ($parsedData->weblinks->weblink as $weblink) {
                $this->weblinks[$i]->title = (string)$weblink->title;
                $this->weblinks[$i]->link = (string)$weblink->link;
                $i++;
            }
        }   

  if(!empty($parsedData->groups)) {
            $this->groups = array();

            $i = 0;
            foreach ($parsedData->groups->group as $group) {

$this->groups[$i]->groupID64 = (string)$group->groupID64; // row 132 in script

                $this->groups[$i]->groupName = (string)$group->groupName;
                $this->groups[$i]->groupURL = (string)$group->groupURL;
                $this->groups[$i]->headline = (string)$group->headline;
                $this->groups[$i]->summary = (string)$group->summary;

                $this->groups[$i]->avatarIcon = (string)$group->avatarIcon;
                $this->groups[$i]->avatarMedium = (string)$group->avatarMedium;
                $this->groups[$i]->avatarFull = (string)$group->avatarFull;

                $this->groups[$i]->memberCount = (string)$group->memberCount;
                $this->groups[$i]->membersInChat = (string)$group->membersInChat;
                $this->groups[$i]->membersInGame = (string)$group->membersInGame;
                $this->groups[$i]->membersOnline = (string)$group->membersOnline; 

                $i++;
            }

        }                    

    }
}
  .

。 . 我已经尝试过使用关联数组,但没有用;也许是全新的。 -_-

所以,我根本无法设置 error_reporting(0) 或 ini_set。

我也尝试使用 new stdClass() 。但是我也没有得到这个运行ning。

你创建了一个数组。

$this->groups = array();

但是在这个数组中你没有创建任何对象。您只需将此数组的元素(未初始化)用作对象。您应该在 132.row.

之前添加此行
$this->groups[$i] = new Group();

或类似的东西。 如果您没有群组 class,您应该尝试

$this->groups[$i] = new stdClass();