plausible / wordpress

Plausible Analytics WordPress plugin
https://plausible.io/wordpress-analytics-plugin
MIT License
50 stars 26 forks source link

PHP Fatal error: Uncaught TypeError: in_array() #175

Closed skyminds closed 7 months ago

skyminds commented 7 months ago

Plausible throws a fatal error, which affects the frontend and backend - PHP Fatal error: Uncaught TypeError: in_array():

2024/02/06 16:53:04 [error] 2043808#2043808: *40 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, string given in /public_html/wp-content/plugins/plausible-analytics/src/Includes/Helpers.php:99
Stack trace:
#0 /public_html/wp-content/plugins/plausible-analytics/src/Includes/Helpers.php(99): in_array()
#1 /public_html/wp-content/plugins/plausible-analytics/src/Includes/Helpers.php(30): Plausible\Analytics\WP\Includes\Helpers::get_filename()
#2 /public_html/wp-content/plugins/plausible-analytics/src/Includes/Actions.php(51): Plausible\Analytics\WP\Includes\Helpers::get_js_url()
#3 /public_html/wp-includes/class-wp-hook.php(324): Plausible\Analytics\WP\Includes\Actions->maybe_register_assets()
#4 /public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
#5 /public_html/wp-includes/plugin.php(517): WP_Hook->do_action()
#6 /public_ht" while reading response header from upstream, client: ***, server: ***, request: "GET / HTTP/2.0", upstream: "fastcgi://unix:/run/php/php8.3-fpm.sock:",

Using the self-hosted version, v2.0.1, with PHP 8.2 and PHP8.3

Dan0sz commented 7 months ago

I've tested this up to PHP 8.2, and I can't reproduce it. $settings['enhanced_measurements'] is always an array, as it's set in $defaults:

image

The error thrown says that $settings['enhanced_measurements'] isn't an array, but a string. Which can't happen, as wp_parse_args() makes sure it's an (empty) array.

What I did to try and reproduce it, is the following:

I'm not getting any errors.

Could you provide a more detailed report on how to reproduce it?

Dan0sz commented 7 months ago

Nevermind. I've added this code to make sure it's an array, never hurts to double check 😄