mollie / gambio

BSD 2-Clause "Simplified" License
4 stars 5 forks source link

Loads of PHP warnings >Constants already defined< #97

Closed Pixopax closed 3 months ago

Pixopax commented 3 months ago

Hello, I receive a ton of warning messages in my Gambio logs:

2024-03-25 13:21:38 WARNING: Constant MODULE_PAYMENT_MOLLIE_BANCONTACT_STATUS_DESC already defined 2024-03-25 13:21:38 WARNING: Constant MODULE_PAYMENT_MOLLIE_BANCONTACT_STATUS_TITLE already defined 2024-03-25 13:21:38 WARNING: Constant MODULE_PAYMENT_MOLLIE_BANCONTACT_TEXT_DESCRIPTION already defined 2024-03-25 13:21:38 WARNING: Constant MODULE_PAYMENT_MOLLIE_BANCONTACT_TEXT_TITLE already defined 2024-03-25 13:21:38 WARNING: Constant MODULE_PAYMENT_MOLLIE_IDEAL_SURCHARGE_LIMIT_DESC already defined 2024-03-25 13:21:38 WARNING: Constant MODULE_PAYMENT_MOLLIE_IDEAL_SURCHARGE_LIMIT_TITLE already defined 2024-03-25 13:21:38 WARNING: Constant MODULE_PAYMENT_MOLLIE_IDEAL_SURCHARGE_PERCENTAGE_DESC already defined 2024-03-25 13:21:38 WARNING: Constant MODULE_PAYMENT_MOLLIE_IDEAL_SURCHARGE_PERCENTAGE_TITLE already defined 2024-03-25 13:21:38 WARNING: Constant MODULE_PAYMENT_MOLLIE_IDEAL_SURCHARGE_FIXED_AMOUNT_DESC already defined 2024-03-25 13:21:38 WARNING: Constant MODULE_PAYMENT_MOLLIE_IDEAL_SURCHARGE_FIXED_AMOUNT_TITLE already defined 2024-03-25 13:21:38 WARNING: Constant MODULE_PAYMENT_MOLLIE_IDEAL_SURCHARGE_TYPE_DESC already defined 2024-03-25 13:21:38 WARNING: Constant MODULE_PAYMENT_MOLLIE_IDEAL_SURCHARGE_TYPE_TITLE already defined 2024-03-25 13:21:38 WARNING: Constant MODULE_PAYMENT_MOLLIE_IDEAL_TRANSACTION_DESCRIPTION_DESC already defined 2024-03-25 13:21:38 WARNING: Constant MODULE_PAYMENT_MOLLIE_IDEAL_TRANSACTION_DESCRIPTION_TITLE already defined

The log is full of it. For every pacment module it has about 30 warnings. This comes up when I empty the cache for modules. Seems as if some constants are defined more than once.

Example:

/httpdocs/shop/lang/german/modules/payment/mollie_bancontact.php line 10 define('MODULE_PAYMENT_MOLLIE_BANCONTACT_CHECKOUT_NAME_TITLE', 'Checkout-Name'); define('MODULE_PAYMENT_MOLLIE_BANCONTACT_CHECKOUT_NAME_DESC', 'Bitte geben Sie den Namen an, der im Checkout angezeigt werden soll.'); define('MODULE_PAYMENT_MOLLIE_BANCONTACT_CHECKOUT_DESCRIPTION_TITLE', 'Checkout-Beschreibung');

/httpdocs/shop/lang/german/modules/payment/mollie_bancontact.php Line 9 define('MODULE_PAYMENT_MOLLIE_BANCONTACT_STATUS_DESC', 'Möchten Sie Zahlungen via Banccontact akzeptieren?'); define('MODULE_PAYMENT_MOLLIE_BANCONTACT_CHECKOUT_NAME_TITLE', 'Checkout-Name'); define('MODULE_PAYMENT_MOLLIE_BANCONTACT_CHECKOUT_NAME_DESC', 'Bitte geben Sie den Namen an, der im Checkout angezeigt werden soll.');

Pixopax commented 3 months ago

This is quite severe, my logs run over from the enormous amount of messages.

Gambio 4.8.0.2 Mollie module 3.0.20 (latest)

I would really apreciate if you could solve this.

Pixopax commented 3 months ago

After checking your code we found that you define all strings in language files with a simple define(), a very old way to do that, and without any checks if the constant was already defined, tsk tsk tsk.. Bad programming habits :-) That leads to these massive logfiles.

Instead of just define('MODULE_PAYMENT_MOLLIE_APPLEPAY_TEXT_TITLE', 'Apple Pay'); it should be defined('MODULE_PAYMENT_MOLLIE_APPLEPAY_TEXT_TITLE') ?: define('MODULE_PAYMENT_MOLLIE_APPLEPAY_TEXT_TITLE', 'Apple Pay');

Should be quite simply to solve this.

Pixopax commented 3 months ago

I wrote a program to convert all the constants so this warning does not pop up any more. here are the files:

french.zip german.zip dutch.zip english.zip

logeecom commented 3 months ago

Hello @Pixopax,

Thank you for reaching out to us regarding this issue.

Please note that we have successfully reproduced the issue that you reported.

As you noticed, the module defines all string constants in language files without checking if the constant was already defined. These constants are defined every time an action is triggered with any payment method in the Mollie module.

We’ve updated the plugin so that it checks for each constant whether it is already defined. This was done for every payment method in each language (4 languages).

The changes will be available in the next plugin version which we expect to release at the beginning of next week.

If you have any questions or concerns, please let us know.

Kind regards

logeecom commented 3 months ago

Hey @Pixopax

Please note that our team fixed this issue. We released the new plugins.

Gambio 4.5-4.x: https://github.com/mollie/gambio/releases/tag/v3.0.21

Gambio 4.1-4.4: https://github.com/mollie/gambio/releases/tag/v2.0.18

Gambio 3.5-4.0: https://github.com/mollie/gambio/releases/tag/v1.0.16

Gambio 3.0 - 3.4: https://github.com/mollie/gambio/releases/tag/v0.1.16

Best regards.

Pixopax commented 3 months ago

Great! Thank you very much.