Firefox PHP

Language file declaring a function crashes

Posted by dmaftei 
Language file declaring a function crashes
November 08, 2007 11:11PM
Hello All,

Does anybody have any idea why a language file that defines a function (or includes another .php file) crashes? I'm experimenting with romanian.php; when I use it as is, everything is fine. But if I add a function to the file, as in:

<?php
function useless($str)
{
return str_replace("foo", "bar", $str);
}

$language="Romanian";
[snip]

then a number of pages come out blank (I noticed 'General Settings' and forum edit in the admin panel, and 'Forum Settings' in the user's control panel.) Note that I'm not even using the function, simply declaring it causes problems...

And btw, if I do use the function, it works. If I go down in the file and do something like:

[snip]
"Activity" => useless("foo bar foobar"),
[snip]

I do get "bar bar barbar" displayed for "Activity".

TIA
dmaftei



Edited 1 time(s). Last edit at 11/08/2007 11:28PM by dmaftei.
Re: Language file declaring a function crashes
November 09, 2007 02:54AM
This would crash if the language file was included more than once.
Can you try the following construction?
if (! function_exists('useless')) {
function useless($str)
{
return str_replace("foo", "bar", $str);
}
}


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Language file declaring a function crashes
November 09, 2007 08:56AM
That did it, thanks.

I take it that some_language.php *is* included from more than one place, right?

Regards,
dmaftei
Re: Language file declaring a function crashes
November 09, 2007 09:08AM
Yes, that would be the only reason for this code to crash. But I do not know why this is the case for you. On my system, the language file appears to be loaded only once.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Language file declaring a function crashes
November 09, 2007 09:23AM
As long as the multiple inclusion protection works, that's fine... Maybe one day (if I find the time...) I'll trace trough the code to understand what's going on.

Regards,
dmaftei
Re: Language file declaring a function crashes
November 09, 2007 11:11AM
In certain parts of the admin, it may be loaded more than once to fill in a drop down box.

Brian - Cowboy Ninja Coder - Personal Blog - Twitter
Re: Language file declaring a function crashes
November 09, 2007 12:40PM
That makes me wonder why is it loaded at all, since the admin panel doesn't seem to be internationalized...

Thanks both of you for your help and promptness, I appreciate it.

Regards,
dmaftei
Re: Language file declaring a function crashes
November 09, 2007 01:50PM
because there are select-boxes to select the language-files for a forum or as default.


Thomas Seifert
Re: Language file declaring a function crashes
November 09, 2007 02:18PM
Quote
ts77
because there are select-boxes to select the language-files for a forum or as default.

Ah, so you fill in the list with the "$language"s from each file, and in order to get to "$language" you need to load the file. Got it.

Regards,
dmaftei
Sorry, only registered users may post in this forum.

Click here to login