Error handling for local conf #469

Closed
opened 2026-10-05 00:00:04 +02:00 by adam · 2 comments
Owner

I wrote functions to use stronger bcrypt hashes instead of the default ones. This worked like a charm on all pages but the Configurations->Options page. There only a blank page was shown but no error or warning anywhere, but in the browser, nor in the apache error_log. After digging in the code I found out that a redeclaration of my hashing functions was the cause. Unfortunatly this simple error was completely hidden by the usage of @include in https://github.com/Piwigo/Piwigo/blob/4d75cf/admin/configuration.php#L326

As this will happen for every error in the local config (and users will tend to make mistakes there) I suggest to change the above mentioned line to something like
if(is_readable(PHPWG_ROOT_PATH. 'local/config/config.inc.php') { include(PHPWG_ROOT_PATH. 'local/config/config.inc.php');

BTW: Can't https://github.com/Piwigo/Piwigo/blob/4d75cf/admin/configuration.php#L326-L330 be simplified to just use PHPWG_ROOT_PATH.PWG_LOCAL_DIR. 'config/config.inc.php'?

What's the preferred way of avoiding function redeclaration errors? Use of function_exists around functions in local conf or to make sure the local conf is only included once programmatically, for example by using include_once? If you go for the first, this should be documented somewhere (I did not find it in the wiki nor in the default local conf nor in the forum). The second might have side effects I'm not aware of.

Thanks
e-dschungel

I wrote functions to use stronger bcrypt hashes instead of the default ones. This worked like a charm on all pages but the Configurations->Options page. There only a blank page was shown but no error or warning anywhere, but in the browser, nor in the apache error_log. After digging in the code I found out that a redeclaration of my hashing functions was the cause. Unfortunatly this simple error was completely hidden by the usage of @include in https://github.com/Piwigo/Piwigo/blob/4d75cf/admin/configuration.php#L326 As this will happen for every error in the local config (and users will tend to make mistakes there) I suggest to change the above mentioned line to something like ` if(is_readable(PHPWG_ROOT_PATH. 'local/config/config.inc.php') { include(PHPWG_ROOT_PATH. 'local/config/config.inc.php'); ` BTW: Can't https://github.com/Piwigo/Piwigo/blob/4d75cf/admin/configuration.php#L326-L330 be simplified to just use PHPWG_ROOT_PATH.PWG_LOCAL_DIR. 'config/config.inc.php'? What's the preferred way of avoiding function redeclaration errors? Use of function_exists around functions in local conf or to make sure the local conf is only included once programmatically, for example by using include_once? If you go for the first, this should be documented somewhere (I did not find it in the wiki nor in the default local conf nor in the forum). The second might have side effects I'm not aware of. Thanks e-dschungel <!-- github-sync-id:159813671 -->
adam closed this issue 2026-10-05 00:00:05 +02:00
Author
Owner

Hi @e-dschungel

The problem with if(is_readable($file)){include($file)} is that it may completely break your Piwigo if you have errors in your $file. Thus the @include.

If you want to have your custom function in your local configuration, then we recommend the function_exists. I have updated http://piwigo.org/doc/doku.php?id=user_documentation:use:features:conf_locale to reflect this.

PWG_LOCAL_DIR doesn't have to be "local", in case of multiple site, so no, we need to perform 2 includes.

Hi @e-dschungel The problem with `if(is_readable($file)){include($file)}` is that it may completely break your Piwigo if you have errors in your $file. Thus the `@include`. If you want to have your custom function in your local configuration, then we recommend the `function_exists`. I have updated http://piwigo.org/doc/doku.php?id=user_documentation:use:features:conf_locale to reflect this. PWG_LOCAL_DIR doesn't have to be "local", in case of multiple site, so no, we need to perform 2 includes. <!-- github-comment-id:231580047 -->
Author
Owner

Thanks for clarifying and updating the documentation.

Thanks for clarifying and updating the documentation. <!-- github-comment-id:233180720 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/Piwigo#469