Search code examples
phpinvision-power-board

Class already declared in PHP and IP.Content?


I am including a file with a class GroupManager which is eval'd with IP.content. I have received the error that the class is already defined. If I un-include, I receive no errors. If I rename the class, I receive no errors (however I am certain this class does not exist elsewhere.) I tried the following in case there were multiple includes (I was personally using include_once...):

if( !class_exists('GroupManager') ) {
    class GroupManager {
    }
}

I still receive the error:

 Cannot redeclare class GroupManager in ... GroupManager.php on line 37

Obviously there is no line 37 in my 4-line file.

If I remove the class declaration, and replace it with an echo, I receive no error and it echos fine, which means the class does not exist at that point.

if( !class_exists('GroupManager') ) {
    echo "Class does not exist???";
}

I am unsure how to even debug this.


Solution

  • I found the issue, and I should have caught it a lot sooner... Another administrator had included this file in a hook. The hook is apparently run on every page, even though every page does not require the hook... Thus it was not my thought to check the hooks.

    If anyone has weird include issues with IPB, make sure you grep for the includes/requires. It'll save you a lot of hassle.

    Something like this should give you an idea of where the file is being included:

    grep -r include_name.php .
    

    This will check all files recursively from the current dir.