0

I'm getting a PHP fatal error:

Fatal error: Cannot redeclare getString() (previously declared in path/src/scripts/php/functions.php:66) in path/src/scripts/php/functions.php on line 111

These files are included:

  1. index.php which "is" the page
  2. functions.php which is called by index.php via require_once. It includes all the functions and stuff
  3. error.php which is called by functions.php when an error in the given function appears. error.php calls functions.php, but only via require_once, so in this case it should not call the functions.php a second time

I usually know what that error means. But this function is only declared once. Also, the error only occurs when I call it in another function within the functions.php.

Here is the function:

function getString($key, $lang) {
if (!is_string($key) || !is_string($lang)) {
    $fehlercode = "StringNoString";
    require_once ("path/src/logs/error.php");
    exit;
}
$urkey = $key;
$key = (String) $key;
if (strlen($key) < 5) {
    switch (strlen($key)) {
        case 4:
            $key = "0".$key;
            break;
        case 3:
            $key = "00".$key;
            break;
        case 2:
            $key = "000".$key;
            break;
        case 1:
            $key = "0000".$key;
            break;
        default:
            break;
    }
}
global $de_Array, $en_Array;

if ($lang == "en") {
    if (array_key_exists($key, $en_Array)) {
        return $en_Array[$key];
    } else {
        $fehlercode = "NoStringOn(".$key."en)";
        require_once ("path/src/logs/error.php");
        exit;
    }
} else {
    if (array_key_exists($key, $de_Array)) {
        return $de_Array[$key];
    } else {
        $fehlercode = "NoStringOn(".$key."de)";
        require_once ("path/src/logs/error.php");
        exit;
    }
}
}

It works, when I call it in index.php like this:

<? echo getString("00004", $prefLang); ?>

But it doesn't work, when I call the function from within another function in functions.php like this:

$faqs = '<div class="zweispaltigEZ"><div class="left"><h3>'.getString("00087", $prefLang).'</h3><ol>'.$questions.'</ol></div><div class="right"><h3>'.getString("00088", $prefLang).'</h3>'.$answers.'</div></div>';
return $faqs;

There is nothing wrong with the function calling getString(), because when I replace it with hardcoded text, it works.


EDIT

I "solved" the fatal error by removing the code that calls the error.php and the exits. However, now, the getString() function still doesn't function properly. Calling it directly from the index.php (like above) works fine, but calling it within another function leads to no output at all.

4

0 回答 0