This set of lines is producing an error "Trying to get property of non object":

         foreach($feeds as $feed) {
            if ($feed->type == "atom" && $feed->content == "main") {
              $trackback_found = _trackback_feed_search($feed->url, $link, $nodepath);
            }

Now, running it through my debugger at this point I can see that both $feeds and $feed are populated. $feeds is a two dimensional array resulting from looking through an html document and parsing out the url, type and content of an rss/atom link in the document.

So I have

$feeds [0][url] = something
$feeds [0][type] = something
$feeds [0][content] = something
$feeds [1][url] = something
$feeds [1][type] = something
$feeds [1][content] = something
etc...

And I'm trying to look through each $feeds[] by naming each one $feed - which should therefore be a three element array in its own right with url, type and content entries.

I suspect I need one of those

foreach($feeds as $key => $value) type constructs but am not sure how to do it - what the $key and $value apply to?

Anyone help in a hurry?

Cheers,

Jock

Comments

zoo33’s picture

The answer is simple: you're trying to reference an object property ($object->property) when what you actually have is an array element ($array['element']).

jockox3@drupal.org’s picture

Thanks...

I just worked out something similar for myself too! Now for the follow-up if I may....

I fixed it by changing my snippet above to:

          foreach($feeds as $key => $feed) {
            if ($feed["type"] == "atom" && $feed["content"] == "main") {
              $trackback_found = _trackback_feed_search($feed["url"], $link, $nodepath);
            }
          }

Question - do I actually need the "$feeds as $key => $feed" change or can I go back to "$feeds as $feed" so long as I continue to use the array element access mechanism "$feed["type"] == "atom"" ?

Cheers,

Jock

styro’s picture

If you don't need/want the array key for anything inside the loop, then yes you can leave it out.

--
Anton
New to Drupal? | Troubleshooting FAQ
Example knowledge base built with Drupal

lhm0802’s picture

very good,i can made it !
-
Healthy home