Got this error:
PHP Fatal error: Cannot use object of type stdClass as array in /var/www/likwid/test/www/sites/all/modules/contrib/feeds/libraries/common_syndication_parser.inc on line 276
PHP Stack trace:
PHP 1. {main}() /var/www/drush/drush/drush.php:0
PHP 2. drush_main() /var/www/drush/drush/drush.php:37
PHP 3. drush_dispatch() /var/www/drush/drush/drush.php:78
PHP 4. call_user_func_array() /var/www/drush/drush/includes/drush.inc:23
PHP 5. drush_command() /var/www/drush/drush/includes/drush.inc:0
PHP 6. call_user_func_array() /var/www/drush/drush/includes/command.inc:288
PHP 7. drush_invoke() /var/www/drush/drush/includes/command.inc:0
PHP 8. call_user_func_array() /var/www/drush/drush/includes/command.inc:240
PHP 9. drush_core_cron() /var/www/drush/drush/includes/command.inc:0
PHP 10. drupal_cron_run() /var/www/drush/drush/commands/core/core.drush.inc:346
PHP 11. module_invoke_all() /var/www/likwid/test/www/includes/common.inc:2693
PHP 12. call_user_func_array() /var/www/likwid/test/www/includes/module.inc:471
PHP 13. feeds_cron() /var/www/likwid/test/www/includes/module.inc:0
PHP 14. FeedsScheduler->cron() /var/www/likwid/test/www/sites/all/modules/contrib/feeds/feeds.module:33
PHP 15. FeedsScheduler->work() /var/www/likwid/test/www/sites/all/modules/contrib/feeds/includes/FeedsScheduler.inc:142
PHP 16. FeedsSource->import() /var/www/likwid/test/www/sites/all/modules/contrib/feeds/includes/FeedsScheduler.inc:220
PHP 17. FeedsSyndicationParser->parse() /var/www/likwid/test/www/sites/all/modules/contrib/feeds/includes/FeedsSource.inc:112
PHP 18. common_syndication_parser_parse() /var/www/likwid/test/www/sites/all/modules/contrib/feeds/plugins/FeedsSyndicationParser.inc:16
PHP 19. _parser_common_syndication_RDF10_parse() /var/www/likwid/test/www/sites/all/modules/contrib/feeds/libraries/common_syndication_parser.inc:42
Drush command could not be completed.
See file common_syndication_parser.inc at line 316:
function _parser_common_syndication_RDF10_item($rdf_data, $mappings) {
foreach (get_object_vars($mappings) as $k => $v) {
if (is_object($v)) {
$mappings->$k = _parser_common_syndication_RDF10_item($rdf_data, $v);
}
else {
$values = _parser_common_syndication_RDF10_property($rdf_data, $v);
$mappings->$k = !is_array($values) || count($values) > 1 ? $values : reset($values);
}
}
return (object)$mappings;
}
There is an explicit cast of element as an object in the return statement.
And here (line 262):
// Declaratively define mappings that determine how to construct the result object.
$item = _parser_common_syndication_RDF10_item($rdf_data, (object)array(
'title' => array('rss:title', 'dc:title'),
'description' => array('rss:description', 'dc:description', 'content:encoded'),
'options' => (object)array(
'guid' => 'rdf:about',
'timestamp' => 'dc:date',
'author' => array('dc:creator', 'dc:publisher'),
'url' => array('rss:link', 'rdf:about'),
'tags' => 'dc:subject',
),
));
// Special handling for the title:
$item['title'] = _parser_common_syndication_title($item['title'], $item['description']);
You use it has an array, this is no good, either you should normalize (all array, or all object) or you should do an explicit cast before using the object as an array:
// Declaratively define mappings that determine how to construct the result object.
$item = _parser_common_syndication_RDF10_item($rdf_data, (object)array(
'title' => array('rss:title', 'dc:title'),
'description' => array('rss:description', 'dc:description', 'content:encoded'),
'options' => (object)array(
'guid' => 'rdf:about',
'timestamp' => 'dc:date',
'author' => array('dc:creator', 'dc:publisher'),
'url' => array('rss:link', 'rdf:about'),
'tags' => 'dc:subject',
),
));
// Explicit cast
$item = (array) $item;
// Special handling for the title:
$item['title'] = _parser_common_syndication_title($item['title'], $item['description']);
The error is fatal with PHP >= 5.3, I'm not sure about PHP <= 5.2.
| Comment | File | Size | Author |
|---|---|---|---|
| #35 | 701390-35_rss1_tests.patch | 24.75 KB | alex_b |
| #34 | 701390-34_rss1_tests.patch | 24.33 KB | alex_b |
| #32 | 701390-32_rss1_tests.patch | 24.27 KB | alex_b |
| #29 | common_syndication_parser_1_no_title_to_author_name.patch | 3.28 KB | frega |
| #17 | common_syndication_parser.patch | 2.94 KB | Mixologic |
Comments
Comment #1
rbrandon commentedWhat is the standard for this going to be object or array? I can submit a patch if nobody is willing I just need to know what the standard will be.
Comment #2
rbrandon commentedComment #3
pounardI don't know who wrote this code, but this person should know well the API he uses, so the standard too.
Comment #4
swanpoint commentedUsing Feeds to eat an RSS feed cooked by Perl's XML::RSS, I have also choked on this bug. Attached is a patch that worked for me. UPDATE: I found that using '->' breaks Feeds when importing an RSS feed into a node object, I only get 1 node instead of the 15 I should've got. So, casting via the '(array)' method might be the better solution; ref. http://drupal.org/node/720116#comment-2691590 . UPDATE2: mn_rdf10_beta8.patch works like a charm.
Comment #5
alex_b commented#720116: Getting Cron Error "cannot use object of type stdClass as array..." and this issue are duplicates. #4 needs to be reconciled with #720116-1: Getting Cron Error "cannot use object of type stdClass as array..." and vice versa. This issue prevails in HEAD, hence setting issue to 6.x-1.x.
Comment #6
alex_b commentedComment #7
darrenmothersele commentedsubscribe
Comment #8
frega commentedsorry, i missed this issue and posted my patch (mn_rdf10_beta8.patch) mentioned in comment #4 and #5 over at #720116: Getting Cron Error "cannot use object of type stdClass as array...".
i've tried to make sure that the mn_rdf10_beta8.patch returns an identically structured array ($parsed_source) like the other "parsers" - i used _parser_common_syndication_RSS20_parse() as reference; the convention seems to be array only - but i might be wrong as I am new to Feeds.
The current function mixes object and array-casting, and the feeds.patch above casts to object rather than array.
This whole object/array-casting could be avoided if _parser_common_syndication_RDF10_item was slightly rewritten (which i am happy to do, if the project owners want me to).
Comment #9
pounard@frega #8, Agree, to much cast kills the cast.
Comment #10
frega commentedRolled a new patch, incorporating the old patch (#8) and simplifying _parser_common_syndication_RDF10_item-function and the individual $item-array. The individual item-array *will not* have an 'options'-key anymore. This does not seem to be needed further down the chain (i might be wrong, tho :| ) - the other parsers don't provide an 'options'-key in their items, anyway.
Sorry for unusual path in the patch - am only using feeds in mn-context; a patch -p0 should apply (can only verify right now against 6.x-1.0-alpha11 as that's mn_beta8) if you adjust the filename on the prompt accordingly.
Comment #11
pounard#10 Path can be manually edited in your patch after you did it, easy to edit and submit it without having to use the patch or cvs command.
Comment #12
alex_b commented#10 Looks very good. pounard: can you confirm that #10 addresses the error that you initially reported?
Comment #13
pounard@alex_b #12 : I'll do it as soon as I can.
Comment #14
geerlingguy commentedSub.
Comment #15
gregglesI had the same problem on a feed from craigslist using Managing News 1.0-beta8 and applying this patch removed the error (there were no new items, so I can't say they parsed correctly).
I don't know enough about the parser to say that this is "ready to commit" but it seemed to solve the problem.
Comment #16
MixologicUI re-rolled the patch with the correct path info,
Removed the extra:
+ 'author' => array('dc:creator', 'dc:publisher'),
(there were two)
And additionally, the parse function in FeedsSyndicationParser.inc was expecting a
field called link, which it sets on the FeedsBatch object, and everwhere else it was a string, vs an object. Granted getLink() is never called anywhere, but just in case it does...
$parsed_source = array(
'title' => _parser_common_syndication_title((string)$rss_channel->title),
'description' => (string)$rss_channel->description,
- 'options' => (object)array('link' => (string)$rss_channel->link),
+ 'link' => (string)$rss_channel->link,
'items' => array(),
);
Edit: er.. whoops.. accidentally attached it twice.
Comment #17
MixologicNoticed one more thing: $item['author'] never gets explicitly set to $item['author_name'] which is what the mapper is looking for.
re-re-rolled patch with that fix.
Note that Im in strong disagreement with this bit:
if (empty($item['author_name'])) {
$item['author_name'] = $parsed_source['title'];
}
But Im leaving it there so as to not break existing functionality. But I for one certainly dont want titles in my author field, simply because its empty.
Comment #18
geerlingguy commentedSetting status.
Comment #19
alex_b commented#17:
Need more time for thorough review, but this is what I find right away:
A Not sure whether switching to author_name without making sure that author_name will make the parser work - look at FeedsSyndicationParser::getMappingSources().
B I agree, let's drop using title as author (sic!) fallback. Is this happening anywhere else?
Setting this to critical, as I'd love to roll a fix into upcoming alpha14.
Comment #20
MixologicYeah actually thats why I set it to author_name
Line 42 of FeedSyndicationParser:
Comment #21
frega commentedThe patch #17 works well for me - and I agree the title as fallback for author_name should go :) Could not find any other occurences of "author".
In trying to figure out whether there are any I made an overview of what is mapped how in the the common_syndication_parser.inc (because it is a little confusing in places) - please see here:
http://spreadsheets.google.com/ccc?key=0AsaFss74KTikdGU4YWhMdXhQbnBHazNQ...
Maybe this can help revising / harmonising the way the different formats are parsed / mapped and which fallbacks are used (e.g. currently time() is a fallback for timestamp in RSS2.0, but not in the others and so on)
Comment #22
alex_b commented#20: But shouldn't author_name be a string, not an array?
Comment #23
frega commented#20 is only referring to the FeedsSyndicationParser::getMappingSources()-definitions in profiles/managingnews/modules/contrib/feeds/plugins/FeedsSyndicationParser.inc; all occurences of 'author_name' in the common_syndication_parser.inc are strings.
Comment #24
alex_b commented#23: Thanks for clarification, I misread
'author_name' => array('dc:creator', 'dc:publisher'),- apologies for confusion.Comment #25
Anonymous (not verified) commentedIm still experienceing this bug with today's April 12th release on trying to import a regular Drupal frontpage XML RSS (domain.com/rss.xml -- basic Drupal RSS...)
which is this line:
It happens on
node/add/feedtrying to import this feed:http://www.magentosites.net/rss.xml
Comment #26
Anonymous (not verified) commentedHere is the solution:
1. before line 276, add this trick
$item = (array) $item;2. comment // this line:
$item['rdf'] = (object)array();This is not intended as a patch, someone with better affiliation of this module should try to clean up the object/array mix&match mess.
Comment #27
frega commented@morningtime - i just checked - this patch has not made it into mn-beta9 ...
@alexb - do you need more input? - can i be of any assistance regarding this issue / patch?
Comment #28
alex_b commentedfrega - This is just waiting on a patch including #19 B . If you could provide one and make sure that this patch is passing all tests, that would be of great help!
Comment #29
frega commentedalex_b: sorry this took so long, please find patch attached; tested it with several RSS1.0 feeds (mn_beta9 dies on "adding" a new RSS1 feed, after patch it doesn't).
couldn't find any info on how to run mn-tests, tho - if you give me a hint how to set that up, i'll be more than happy to do that - if patch in #19 passed, this should pass as well ... famous last words, i guess :) hope you guys have a great drupalcon.
Comment #30
geerlingguy commentedLet's see if this one is acceptable. I will test later if I have time.
Comment #31
geerlingguy commentedPatch applied cleanly for me on my managing news site; so far so good... but the emails only come every hour or two (on certain feeds). If none come in through the rest of the day, I'd say this patch fixes the problem for me.
Comment #32
alex_b commentedI can confirm that patch in #29 allows me to import feed in #25. I've added tests for it, too. See attached patch.
For some reasons tests on feed from #25 fail though. I know this is weird, I'd love if somebody else here could have a look at it.
Comment #33
alex_b commentedHang on, I think this is a character encoding issue. Will report back in a bit.
Comment #34
alex_b commentedOk, this works now. It was really a character encoding issue that occurred when saving the RSS 1.0 feed. Will commit asap.
Comment #35
alex_b commentedCommitted. Thank you everybody. Final patch attached.