TypeError on photos_add with hide_warnings = true #1710

Open
opened 2026-10-05 00:53:44 +02:00 by adam · 1 comment
Owner

Hello !

I just installed piwigo to try it and ran into an error: When I visited the photos_add page I had a warnings about some php config values. I tried to hide the warning and the page reloaded into an error :

Warning: Undefined array key "setup_warnings" in /var/www/piwigo/_data/templates_c/p6jhns^a89b9dd2b03da870ac5f8f79b4ece1a8cca1ddc7_0.file.photos_add_direct.tpl.php on line 488

Warning: Attempt to read property "value" on null in /var/www/piwigo/_data/templates_c/p6jhns^a89b9dd2b03da870ac5f8f79b4ece1a8cca1ddc7_0.file.photos_add_direct.tpl.php on line 488

Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in /var/www/piwigo/_data/templates_c/p6jhns^a89b9dd2b03da870ac5f8f79b4ece1a8cca1ddc7_0.file.photos_add_direct.tpl.php:488 Stack trace: #0 /var/www/piwigo/include/smarty/libs/sysplugins/smarty_template_resource_base.php(123): content_64dde9cc6a1609_83470618() #1 /var/www/piwigo/include/smarty/libs/sysplugins/smarty_template_compiled.php(114): Smarty_Template_Resource_Base->getRenderedTemplateCode() #2 /var/www/piwigo/include/smarty/libs/sysplugins/smarty_internal_template.php(216): Smarty_Template_Compiled->render() #3 /var/www/piwigo/include/smarty/libs/sysplugins/smarty_internal_templatebase.php(238): Smarty_Internal_Template->render() #4 /var/www/piwigo/include/smarty/libs/sysplugins/smarty_internal_templatebase.php(116): Smarty_Internal_TemplateBase->_execute() #5 /var/www/piwigo/include/template.class.php(469): Smarty_Internal_TemplateBase->fetch() #6 /var/www/piwigo/include/template.class.php(392): Template->parse() #7 /var/www/piwigo/admin/photos_add_direct.php(158): Template->assign_var_from_handle() #8 /var/www/piwigo/admin/photos_add.php(73): include('...') #9 /var/www/piwigo/admin.php(345): include('...') #10 {main} thrown in /var/www/piwigo/_data/templates_c/p6jhns^a89b9dd2b03da870ac5f8f79b4ece1a8cca1ddc7_0.file.photos_add_direct.tpl.php on line 488

I dug into the php files and found the cause of the error : When you enable hide_warnings, setup_warnings doesn't get set in the template variables, and thus count() is called on a null value in the template.

I fixed the error by setting the variable to an empty array if hide_warnings is enabled but there might be better ways to go about it:

diff --git a/admin/include/photos_add_direct_prepare.inc.php a/admin/include/photos_add_direct_prepare.inc.php
216a217,222
> } else {
>   $template->assign(
>     array(
>       'setup_warnings' => array()
>       )
>     );
Hello ! I just installed piwigo to try it and ran into an error: When I visited the photos_add page I had a warnings about some php config values. I tried to hide the warning and the page reloaded into an error : ``` Warning: Undefined array key "setup_warnings" in /var/www/piwigo/_data/templates_c/p6jhns^a89b9dd2b03da870ac5f8f79b4ece1a8cca1ddc7_0.file.photos_add_direct.tpl.php on line 488 Warning: Attempt to read property "value" on null in /var/www/piwigo/_data/templates_c/p6jhns^a89b9dd2b03da870ac5f8f79b4ece1a8cca1ddc7_0.file.photos_add_direct.tpl.php on line 488 Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in /var/www/piwigo/_data/templates_c/p6jhns^a89b9dd2b03da870ac5f8f79b4ece1a8cca1ddc7_0.file.photos_add_direct.tpl.php:488 Stack trace: #0 /var/www/piwigo/include/smarty/libs/sysplugins/smarty_template_resource_base.php(123): content_64dde9cc6a1609_83470618() #1 /var/www/piwigo/include/smarty/libs/sysplugins/smarty_template_compiled.php(114): Smarty_Template_Resource_Base->getRenderedTemplateCode() #2 /var/www/piwigo/include/smarty/libs/sysplugins/smarty_internal_template.php(216): Smarty_Template_Compiled->render() #3 /var/www/piwigo/include/smarty/libs/sysplugins/smarty_internal_templatebase.php(238): Smarty_Internal_Template->render() #4 /var/www/piwigo/include/smarty/libs/sysplugins/smarty_internal_templatebase.php(116): Smarty_Internal_TemplateBase->_execute() #5 /var/www/piwigo/include/template.class.php(469): Smarty_Internal_TemplateBase->fetch() #6 /var/www/piwigo/include/template.class.php(392): Template->parse() #7 /var/www/piwigo/admin/photos_add_direct.php(158): Template->assign_var_from_handle() #8 /var/www/piwigo/admin/photos_add.php(73): include('...') #9 /var/www/piwigo/admin.php(345): include('...') #10 {main} thrown in /var/www/piwigo/_data/templates_c/p6jhns^a89b9dd2b03da870ac5f8f79b4ece1a8cca1ddc7_0.file.photos_add_direct.tpl.php on line 488 ``` I dug into the php files and found the cause of the error : When you enable hide_warnings, [setup_warnings doesn't get set in the template variables](https://github.com/Piwigo/Piwigo/blob/29ccabc89f4b00f67731e612cf84c8f16beaaa53/admin/include/photos_add_direct_prepare.inc.php#L184), and thus [count() is called on a null value](https://github.com/Piwigo/Piwigo/blob/29ccabc89f4b00f67731e612cf84c8f16beaaa53/admin/themes/default/template/photos_add_direct.tpl#L404) in the template. I fixed the error by setting the variable to an empty array if hide_warnings is enabled but there might be better ways to go about it: ```diff diff --git a/admin/include/photos_add_direct_prepare.inc.php a/admin/include/photos_add_direct_prepare.inc.php 216a217,222 > } else { > $template->assign( > array( > 'setup_warnings' => array() > ) > ); ``` <!-- github-sync-id:1854705329 -->
Author
Owner

any update on this, it’s preventing me uploading files on web.

any update on this, it’s preventing me uploading files on web. <!-- github-comment-id:2094917792 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/Piwigo#1710