I have the following code, which works correctly. The Twitter Friends are listed correctly, however it seems that when the last item is displayed the error "Notice: Trying to get property of non-object" is displayed 4 times.
Since the code works as it should, I would like a way to hide these errors.
$connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
$tweets6 = $connection->get("https://api.twitter.com/1.1/friends/list.json?screen_name=".$twitteruser."&count=".$notweets);
foreach ($tweets6 as $tweet)
{
for($i = 0; $i < count($tweet); $i++)
{
echo $tweet[$i] -> name;
echo "<br />";
}
}
you can add a checker if the object has a certain property before using its value
if (isset($tweet[$i]->name)) {
// process
}
Use a simple if condition before print..
$connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
$tweets6 = $connection->get("https://api.twitter.com/1.1/friends/list.json?screen_name=".$twitteruser."&count=".$notweets);
foreach ($tweets6 as $tweet)
{
for($i = 0; $i < count($tweet); $i++){
if($tweet[$i]){
echo $tweet[$i] -> name;
echo "<br />";
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With