Firefox PHP

Language file declaring a function crashes

Posted by dmaftei 
Language file declaring a function crashes
November 09, 2007 05:11AM
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/09/2007 05:28AM by dmaftei.
Re: Language file declaring a function crashes
November 09, 2007 08: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 02:56PM
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 03:08PM
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 03:23PM
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 05:11PM
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 06: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 07:50PM
because there are select-boxes to select the language-files for a forum or as default.


Thomas Seifert
Phorum Development Team / Mysnip-Solutions.de
Custom Phorum and general software development
worry-free Phorum Hosting
Re: Language file declaring a function crashes
November 09, 2007 08: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