Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#278 Cannot redeclare maildir_name_hook()

v2.3.5
closed-fixed
nobody
Core (82)
5
2012-06-30
2012-06-29
Martijn
No

This was reported earlier in #3305278 but closed because it could not be reproduced, but I just ran into this so here to see if we can get this solved forever ;-)

When this occured, I just downloaded the 2.3.5 tar.gz. Unpacked. Then began editting the config first, going through all the options one by one. I didn't use my previous config file which was from 2.3.3, and I didn't copy any other files over from that version. This 2.3.5 was a clean install.

Last thing I changed was maildir_name_hook. I uncommented the function, then attempted to run setup.php for generating a password hash. No error was displayed, but the page stopped rendering right after "Depends on: presence config.inc.php - OK". After the closing </li> there is an empty line in the source, it stops there.

In the logs I found a "PHP Fatal error: Cannot redeclare maildir_name_hook() (previously declared in /home/websites/www/postfixadmin/config.inc.php:172) in /home/websites/www/postfixadmin/config.inc.php on line 179".

Line 172: The line where function maildir_name_hook starts.
Line 179: The line where the function ends by means of a closing curly bracket.

If I uncomment the function completely, setup.php runs fine. Uncommenting it stops setup.php from running.

Looking at setup.php, line 123 and 126: The first one has a require_once() of the config, but the latter has a require() of the config. So in short, it seems that setup.php is loading config.inc.php twice, once by require_once() plus once by using require(), and the second time PHP will complain and halt on redeclaration of maildir_name_hook().

I'm not sure what the intention of this code is; on line 124 it sets $config_loaded = 1 and then it loads the config again. My initial response would be to remove the require() on line 126.

Discussion

    • status: open --> closed-fixed
     
  • Well, actually config.inc.php is already require_once()'d via common.php, so the inclusion via setup.php is basically superfluous - but I'll keep it nevertheless (but only once) ;-)

    Thanks for finding the cause of this issue. I fixed it in SVN r 1405 (2.3 branch). SVN trunk seems to be fixed already.