. Advertisement .
..3..
. Advertisement .
..4..
It is so awful! I encounter the ”notice: trying to get property of non-object” error when I want to use this code to get the player_name variable:
<?
$js = file_get_contents('http://api.convoytrucking.net/api.php?api_key=public&show=player&player_name=Mick_Gibson');
$pjs = json_decode($js);
var_dump($pjs->{'player_name'});
?>
And then I get this error message:
Notice: Trying to get property of non-object in **\htdocs\index.php on line 9 + var_dump() returns: NULL
var_dump($pjs)
returns:
array(1) { [0]=> object(stdClass)#52 (15) { ["player_name"]=> string(11) "Mick_Gibson" ["play
I don’t have any experience about this error. Can someone help me to solve it?
The cause: This error happens because
$pjs
is an object one-element-array.Solution: To solve this error, you should first access the object that represents the array element before accessing its attributes.