Foreach is crashing script, but no errors reported.

Posted by ILMV on Stack Overflow See other posts from Stack Overflow or by ILMV
Published on 2010-04-29T21:38:01Z Indexed on 2010/04/29 21:47 UTC
Read the original article Hit count: 386

Filed under:
|

So I've created this smarty function to get images from my flickr photostream using SimplePie... simple really, or so it should be.

The problem I'm having is the foreach will crash the script, this doesn't happen if I put an exit after the closing foreach, of course because of this the rest of my script doesn't execute. The problem also completely subsides if I remove the foreach, I've tested it and it's not the contents of the foreach, but the loop itself.

Error reporting is turned on but I don't get any, I also tried messing with the memory_limit, with no luck.

Anyone know why this foreach is killing my script?

Thanks!

function smarty_function_flickr ($params, &$smarty) {

    require_once('system/library/SimplePie/simplepie.inc');
    require_once('system/library/SimplePie/idn/idna_convert.class.php');

    $flickr=new flickr();

    /**
    * Set up SimplePie with all default values using shorthand syntax.
    */  
    $feed = new SimplePie($params['feed'], 'system/library/SimplePie/cache', '600');
    $feed->handle_content_type();

    /**
    * What sizes should we use?
    * Choices: square, thumb, small, medium, large.
    */
    $thumb = 'square';
    $full = 'medium';
    $output = array();

    $counter=0;

    // If I comment this foreach out the problem subsides, I know it is not the code within the foreach
    foreach ($feed->get_items() as $item) {

        $url = $flickr->image_from_description($item->get_description());
        $output[$counter]['title'] = $item->get_title();
        $output[$counter]['image'] = $flickr->select_image($url, $full);
        $output[$counter]['thumb'] = $flickr->select_image($url, $thumb);

        $counter++;
    }

    // Set template variables and template
    $smarty->assign('flickr',$output);
    $smarty->display('forms/'.$params['template'].'.tpl');
}

© Stack Overflow or respective owner

Related posts about php

Related posts about simplepie