• Resolved Grzegorz.Janoszka

    (@grzegorzjanoszka)


    I have tons of following PHP errors:

    [29-Dec-2015 18:37:02 UTC] PHP Fatal error: Cannot redeclare image_url() (previously declared in /home/account/wp-content/plugins/global-content-blocks/global-content-blocks.php(248) : eval()’d code:1) in /home/account/wp-content/plugins/global-content-blocks/global-content-blocks.php(248) : eval()’d code on line 5

    Any help on that?

    Thanks for this fantastic plugin!

    https://www.ads-software.com/plugins/global-content-blocks/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Dave Liske

    (@delmarliske)

    Hi Grzegorz … Line 248 in global-content-blocks.php is the third line in this code:


    246: //execute the php code
    247: ob_start();
    248: $result = eval(" ".$content);
    249: $output = ob_get_contents();
    250: ob_end_clean();
    251:
    252: return apply_filters('gcb_block_output', do_shortcode($output . $result));//run the shortcodes as well

    The eval function in PHP evaluates a string as PHP code. What it’s doing in this case is evaluating your own code that you placed in the Content Block. Are you possibly declaring image_url() more than once, in separate blocks on a single page?

    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    Dave,

    Thanks so much for the answer. I have the function declared once and used several times, more or less like that:

    function image_url ($image) {
    if ($image == “tak”) { echo “tak.png”; }
    elseif ($image == “nie”) { echo “nie.png”; }
    else { echo “moze.png”; }
    }
    image_url (“%%paleo%%”);
    image_url (“%%lchf%%”);
    image_url (“%%fodmap%%”);
    image_url (“%%scd%%”);
    image_url (“%%aip%%”);

    I am not PHP hacker, but the code seems to be OK for me. The PHP code with this function is pasted only once.
    I don’t think there is a page with this code twice, I am going to look for it anyway.

    If it happens that I have the same PHP code twice on one page – what can I do to prevent that error from flooding my log files?

    Thank you for so quick and fantastic support!

    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    I think I know where the problem is. At more or less the same time my RSS feed stopped working. My RSS feed for categories shows 10 full last posts and some of them contain the same PHP code with the above function.

    Can it be the cause of the errors? If yes, what can I do to fix it? Maybe testing if a variable is declared and if not, declare the function and this variable – would it help?

    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    OK, I have fixed it using code like below:

    if (!function_exists(‘qux’)) {
    function qux() {}
    }

    Dave, I think it is an important issue, maybe you could add it to the FAQ or so, it could save some time for other people.

    Thanks for the fantastic plugin!

    Plugin Author Dave Liske

    (@delmarliske)

    Hi Grzegorz … I’m adding your solution and a couple other things to the FAQ for the next release. Thanks for the suggestion!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘PHP errors’ is closed to new replies.