"Cannot redeclare plural_en_utf8()" errors

Bug #1239451 reported by Aaron Wells
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mahara
Won't Fix
Low
Unassigned

Bug Description

See https://mahara.org/interaction/forum/topic.php?id=4665&offset=0&limit=10#post24779

Also https://bugs.launchpad.net/mahara-adminlang/+bug/1012580

Under some circumstances, users see the error message "Cannot redeclare plural_en_utf8()". This isn't limited just to the English language pack -- others have reported it for German, "Cannot redeclare plural_de_utf8()".

The error is referring to the "plural_xx_utf8()" method, which is defined inside of the "langconfig.php" lang file. But those who are reporting it only have one copy of the method present in their langconfig file, and indeed inside their entire Mahara installation.

All who have reported it were using Mahara 1.5, so it's possible it may have been fixed in later versions. There is no clear indication of how to replicate this problem.

Tags: lang
Revision history for this message
Aaron Wells (u-aaronw) wrote :

One commenter noted that the problem resolved when they changed lib/mahara.php's get_string_from_file() method so that on line 783 instead of "include ($langfile);" it calls "include_once($langfile);". This would be generally consistent with the error -- if the file is getting included twice, then the function will attempt to be defined twice, throwing this exact error.

The only strange thing is that the include statement is inside an if() block that should prevent it from being executed twice. There's a static $strings variable, and it stores the results of including the language file, and it before loading the language file it checks to see if it is already holding contents for it. So it doesn't make sense that the include() is happening more than once, unless there's some code that can clear out that static $strings, or if its check for whether it has loaded the file before, is not working properly.

Aaron Wells (u-aaronw)
Changed in mahara:
status: Triaged → Incomplete
Revision history for this message
Aaron Wells (u-aaronw) wrote :

Someone reported this error in Mahara 1.7 as well: https://mahara.org/interaction/forum/topic.php?id=5967&offset=0&limit=10#post25454

Perhaps we should implement the suggested fix of changing that include() to an include_once(). Certainly, any file that contains functions *should* be loaded with include_once, and since we put a function in langconfig.php, that's the case. Though on the other hand, I'm puzzled as to *how* this file is getting included more than once. Here's what the function looks like:

function get_string_from_file($identifier, $langfile) {

    static $strings; // Keep the strings cached in memory.

    if (empty($strings[$langfile])) {
        $string = array();
        include ($langfile);
        $strings[$langfile] = $string;
    } else {
        $string = &$strings[$langfile];
    }

    if (!isset ($string[$identifier])) {
        return false;
    }

    return $string[$identifier];
}

The first time langconfig.php is loaded, it should be stored in the static array $strings['langconfig.php'];. Then the next time the function runs through, empty($strings[$langfile]) will return false, and the include() will be skipped. Perhaps there's some quirk in the way include() or static works, which I'm not understanding?

Revision history for this message
Robert Lyon (robertl-9) wrote :

No reports of this problem for years so will close

Changed in mahara:
status: Incomplete → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.