I'm trying to decode json and display results with php but getting nothing back. Could anyone take a look and tell me what I'm doing wrong?
Here is an example of my php :
class League
{
public function __construct($region, $id, $summid) {
global $apiKey;
global $errorAPI;
$data = RIOT_API . "$region/v2.3/league/by-summoner/" . urlencode($summid) . "?api_key=$apiKey";
$info = httpResp($data);
if ($info[1] == false)
{
$League = json_decode(file_get_contents($data) , true);
for ($i = 0; $i < count($League['entries']); $i++)
{
if ($League['entries'][$i]['playerOrTeamId'] == $summid)
{
$floor = $i;
break;
}
}
$this->leaguename = $League['entries'][$floor]['leagueName'];
$this->tier = $League['entries'][$floor]['tier'];
$this->points = $League['entries'][$floor]['leaguePoints'];
$this->rank = $League['entries'][$floor]['rank'];
$this->wins = $League['entries'][$floor]['wins'];
$this->exists = true;
}
else
{
echo "Error " . $info[0] . " - " . array_search($info[0], $errorAPI);
$this->exists = false;
}
}
}
Here is my php for outputting:
$newLeague1 = new League("euw", "Deew0n", "24361317");
echo '<br />League Name : ', $newLeague1->name;
echo "\n";
echo '<br />Position : ', $newLeague1->position;
echo "\n";
echo '<br />League Points : ', $newLeague1->leaguePoints;
echo "\n";
echo '<br />Wins/Losses: ', $newLeague1->wins, "/", $newLeague1->totalgames;
echo "\n";
echo '<br />Division Name: ', $newLeague1->tier, ' ', $newLeague1->rank;
And lastly this is the json I am dealing with : http://pastebin.com/9FKgrjeS
echostatement they don'tvar_dump($League);of $League and lets see what you get in that object. We'll know if it is properly parsed or nothttpResp()? Also, using globals is a terrible way to code. Instead, pass in the dependencies to your class where required.display_errors = Onanderror_reporting = E_ALLin yourphp.inifile and restart your web servertail -f /var/log/apache2/location_to_error.logas an example, in a terminal window and keep it running