Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Warning: Array to string conversion #765

Open
louiswolf opened this issue Feb 7, 2023 · 3 comments · May be fixed by #809
Open

PHP Warning: Array to string conversion #765

louiswolf opened this issue Feb 7, 2023 · 3 comments · May be fixed by #809

Comments

@louiswolf
Copy link

WordPress 6.1.1
WooCommerce: 7.3.0
Mollie Payments: 7.3.5
This issue also existed with older versions.

I get PHP Warnings in my logs from wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-log-handler.php on line 44.

In the Mollie debug logs I find the following, note the 'Array' in the second to last line:

2023-02-07T09:08:56+00:00 DEBUG Creating payment object: type Order, did not fail because of incorrect customerId, so trying Payment now.
2023-02-07T09:08:56+00:00 DEBUG Creating payment object: type Payment, creating a Payment.
2023-02-07T09:08:56+00:00 DEBUG  Order 00000 returnUrl: https://fakewebshopurl.com/checkout/order-received/00000/?key=wc_order_xxxxxxxxxxxxx&order_id=00000&filter_flag=onMollieReturn
2023-02-07T09:08:56+00:00 DEBUG  Order 00000 webhookUrl: https://fakewebshopurl.com/wc-api/mollie_wc_gateway_ideal?order_id=00000&key=wc_order_xxxxxxxxxxxxx&filter_flag
2023-02-07T09:08:56+00:00 DEBUG Array
2023-02-07T09:08:58+00:00 DEBUG setUserMollieCustomerId: Stored Mollie customer ID xxx_XXXXXXXXXX with user 0000

The datestamps match with the PHP warning, so this seems to originate from the mollie-payments-for-woocommerce plugin.

@vHeemstra
Copy link
Contributor

I got a similar warning.

It seems the Mollie Payments plugin sometimes sends an array to the WC logger instead of a string.

Details

PHP: 8.2.8
WordPress: 6.2.2
WooCommerce: 7.9.0
Mollie Payments: 7.3.10

Situation

When proceeding to payment from the checkout page, selecting (Mollie) iDEAL as payment method, but leaving the issuer dropdown to the default empty option (no selected bank), a PHP warning is logged.

(Wordpress has WP_DEBUG on, but with WP_DEBUG_DISPLAY off and WP_DEBUG_LOG on.)

The PHP warning

PHP Warning: Array to string conversion

File: wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-log-handler.php:44

Stack:

WC_Log_Handler::format_entry()
WC_Log_Handler_File::format_entry()
WC_Log_Handler_File->handle()
WC_Logger->log()
Mollie\WooCommerce\Log\WcPsrLoggerAdapter->log()
Mollie\WooCommerce\Log\WcPsrLoggerAdapter->debug()
Mollie\WooCommerce\Payment\PaymentService->processAsMolliePayment()
Mollie\WooCommerce\Payment\PaymentService->processPaymentForMollie()
Mollie\WooCommerce\Payment\PaymentService->processPayment()
Mollie\WooCommerce\Gateway\MolliePaymentGateway->process_payment()
Mollie\WooCommerce\Subscription\MollieSubscriptionGateway->process_payment()
WC_Checkout->process_order_payment()
WC_Checkout->process_checkout()
WC_AJAX::checkout()
do_action('wc_ajax_checkout')
WC_AJAX::do_wc_ajax()
do_action('template_redirect')

Possible cause

Backtracking this, it might be originating here:

Mollie\WooCommerce\Payment\PaymentService::processAsMolliePayment
wp-content/plugins/mollie-payments-for-woocommerce/src/Payment/PaymentService.php:485
--> An array is send to the logger.

Mollie\WooCommerce\Log\WcPsrLoggerAdapter::log
wp-content/plugins/mollie-payments-for-woocommerce/src/Log/WcPsrLoggerAdapter.php:96
--> If $message is not a string, it is just passed on as-is to the WC logger.

(Via WC_Log_Handler_File::format_entry to:)
WC_Log_Handler::format_entry
wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-log-handler.php:44
--> Array is used in string interpolation without conversion

@InpsydeNiklas
Copy link
Collaborator

Mollie Payments for WooCommerce supports PHP versions from 7.2. to 8.1.
PHP 8.2 isn't officially supported at this time. But the team is looking into improving the compatibility.

@vHeemstra
Copy link
Contributor

vHeemstra commented Jul 31, 2023

Mollie Payments for WooCommerce supports PHP versions from 7.2. to 8.1.

PHP 8.2 isn't officially supported at this time. But the team is looking into improving the compatibility.

I put the PHP version there just in case, but the issue is the same for previous PHP versions.

The problem is with this code:

$apiCallLog = [
'amount' => isset($data['amount']) ? $data['amount'] : '',
'description' => isset($data['description'])
? $data['description'] : '',
'redirectUrl' => isset($data['redirectUrl'])
? $data['redirectUrl'] : '',
'webhookUrl' => isset($data['webhookUrl'])
? $data['webhookUrl'] : '',
'method' => isset($data['method']) ? $data['method'] : '',
'issuer' => isset($data['issuer']) ? $data['issuer'] : '',
'locale' => isset($data['locale']) ? $data['locale'] : '',
'dueDate' => isset($data['dueDate']) ? $data['dueDate'] : '',
'metadata' => isset($data['metadata']) ? $data['metadata']
: '',
];
$this->logger->debug($apiCallLog);

It's missing something like json_encode($apiCallLog) as used here:

$this->logger->debug(json_encode($apiCallLog));


And there are more calls with non-string arguments to $this->logger->debug.
(Edit: I was wrong, these use the context argument.)

I'll make a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants