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

Fatal Error with implode() in [give_totals] Shortcode Rendering #23

Open
rafacrt opened this issue Nov 5, 2024 · 0 comments
Open

Fatal Error with implode() in [give_totals] Shortcode Rendering #23

rafacrt opened this issue Nov 5, 2024 · 0 comments

Comments

@rafacrt
Copy link

rafacrt commented Nov 5, 2024

I encountered a fatal error when using the [give_totals] shortcode due to the improper use of implode() within the give_totals.php file. The error occurs when implode() is called on a variable that is not consistently an array, which causes issues in PHP 8 and above.

Error Message:
Fatal error: Uncaught TypeError: implode(): Argument #2 ($array) must be of type array, string given...
File and Line: give_totals.php within the Give Totals widget.

Solution: To resolve this issue, please ensure that the variable being passed to implode() is an array. Here’s a suggested fix to check if the variable is an array before using implode:

// Check if 'ids' is an array before applying implode if (is_array($attributes['ids'])) { $ids = implode(',', $attributes['ids']); } else { $ids = $attributes['ids']; }

Alternatively, this can be handled with a simple fallback in case ids is a string:

$ids = is_array($attributes['ids']) ? implode(',', $attributes['ids']) : $attributes['ids'];

This fix should prevent compatibility issues with PHP 8+.

Environment:
PHP Version: 8.3
GiveWP Version: 2.0.1
WordPress Version: 6.6.2

PHP Version Note:

It's worth mentioning that this error does not occur in PHP 7.4 because it does not enforce strict typing in the same way as PHP 8+. Downgrading to PHP 7.4 can temporarily bypass the issue; however, PHP 7.4 reached its end of active support

Please let me know if further details are needed, and thank you for your attention to this issue!

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

No branches or pull requests

1 participant