Topic: "Hidden" PHP errors

I can't remember if I've already written something about this or not tongue

If you make a mistake in editing, say, lang/[language]/index.php, then you get an error like
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in C:\Apache\Apache2\htdocs\upload\lang\English\index.php on line 7
However, if you make a mistake in lang/[language]/common.php, you get a blank page
Why?

From common.php

// Attempt to load the common language file
@include PUN_ROOT.'lang/'.$pun_user['language'].'/common.php';
if (!isset($lang_common))
    exit('There is no valid language pack \''.pun_htmlspecialchars($pun_user['language']).'\' installed. Please reinstall a language of that name.');

My proposed fix would remove the @ and do a file_exists before the include, something like this:

// Attempt to load the common language file
if (file_exists(PUN_ROOT.'lang/'.$pun_user['language'].'/common.php')
{
    include PUN_ROOT.'lang/'.$pun_user['language'].'/common.php';
    if (!isset($lang_common))
        exit('There is no valid language pack \''.pun_htmlspecialchars($pun_user['language']).'\' installed. Please reinstall a language of that name.');
}
else
    exit('There is no valid language pack \''.pun_htmlspecialchars($pun_user['language']).'\' installed. Please reinstall a language of that name.');

It should accomplish the same goal as the other code while also ensuring that errors in the common lang file get noticed

2 (edited by Smartys 2006-05-12 02:07)

Re: "Hidden" PHP errors

There is a similar issue with config.php (a parse error on that page will cause the whole page to fail silently)
And the issue also affects cache files (and in fact I have to investigate that a bit more, since it might be the cause of some other bug reports)

3 (edited by Smartys 2006-05-12 10:50)

Re: "Hidden" PHP errors

Yeah, cache files are loaded something like this

        // Load cached quickjump
        @include PUN_ROOT.'cache/cache_quickjump_'.$pun_user['g_id'].'.php';
        if (!defined('PUN_QJ_LOADED'))
        {
            require_once PUN_ROOT.'include/cache.php';
            generate_quickjump_cache($pun_user['g_id']);
            require PUN_ROOT.'cache/cache_quickjump_'.$pun_user['g_id'].'.php';
        }

If there is a problem (like for some reason Apache can't read from the folder anymore), strange things happen (ie: with the quickjump the only part that loads is a small bit of the footer)

Re: "Hidden" PHP errors

That's probably a good idea. I'll put it on the list.

"Programming is like sex: one mistake and you have to support it for the rest of your life."