fEmeraldKertelsk
New Member
I found some similar questions, but most seemed to relate to CodeIgniter or SQL queries...We have some error logs running on a website, and we are receiving this error rather regularly:\[code\][30-Nov-2012 11:32:08] PHP Notice: Trying to get property of non-object in index.php on line 25[30-Nov-2012 11:32:08] PHP Warning: Invalid argument supplied for foreach() in index.php on line 25\[/code\]This is in regards to an in-house XML powered RSS feeds which I am tapping into. Here is my query function to get XML Objects:\[code\]function articleTrendingRequest() { $url = "http://www.somedomain.com/article_trending_request.php"; $parameterDatahttp://stackoverflow.com/questions/13805313/= ""; // setup CURL $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $parameterData); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 20); // send $response = trim(urldecode(curl_exec($ch))); // parse response $trendingObjects = @simplexml_load_string($response); return $trendingObjects;}\[/code\]I'll instantiate the function on the page like so \[code\]$trendingObjects = articleTrendingRequest();\[/code\]And then foreach like this:\[code\]<?php foreach ($trendingObjects->articleResult as $articleResult) { ?><td> <div class="articleResult"> <a href="http://stackoverflow.com/questions/13805313/<?php echo"$path2root" ?>/article/article.php?articleId=<?php echo $articleResult->articleId; ?>"> <img src="http://stackoverflow.com/questions/13805313/<?php echo $articleResult->image; ?>"> </a> <h3> <a href="http://stackoverflow.com/questions/13805313/<?php echo"$path2root" ?>/article/article.php?articleId=<?php echo $articleResult->articleId; ?>"> <?php echo truncateTitle($articleResult->title); ?> </a> </h3> </div></td><?php } ?>\[/code\]What are some reasons as to why this error would be coming through in our logs? Everything will render fine on the doc. How can I effectively remedy the errors?I saw in some similar posts that changing the \[code\]foreach\[/code\] to a \[code\]while\[/code\] with array notation may resolve the issues, but these are XML Objects, so I am unclear as to if or why that should be a solution.