query-monitor
query-monitor copied to clipboard
PHP Fatal error: Uncaught TypeError: preg_match() expects parameter 2 to be string
After upgrading to the latest version at the time (3.11.1) we are seeing the following error in logs:
[06-Feb-2023 09:01:06 UTC] PHP Fatal error: Uncaught TypeError: preg_match() expects parameter 2 to be string, null given in /var/www/html/wp-content/plugins/query-monitor/collectors/request.php:312
Stack trace:
#0 /var/www/html/wp-content/plugins/query-monitor/collectors/request.php(312): preg_match('#^^wc-auth/v([1...', NULL)
#1 /var/www/html/wp-content/plugins/query-monitor/classes/Collectors.php(84): QM_Collector_Request->process()
#2 /var/www/html/wp-content/plugins/query-monitor/classes/Dispatcher.php(108): QM_Collectors->process()
#3 /var/www/html/wp-content/plugins/query-monitor/dispatchers/Html.php(352): QM_Dispatcher->get_outputters('html')
#4 /var/www/html/wp-content/plugins/query-monitor/dispatchers/Html.php(316): QM_Dispatcher_Html->before_output()
#5 /var/www/html/wp-includes/class-wp-hook.php(287): QM_Dispatcher_Html->dispatch('')
#6 /var/www/html/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters(NULL, Array)
#7 /var/www/html/wp-includes/plugin.php(484): WP_Hook->do_action(Array)
#8 /var/www/html/wp-includes/load.php(1052): do_a in /var/www/html/wp-content/plugins/query-monitor/collectors/request.php on line 312
It seems to occur after logging in as admin, then being redirected; I've seen it once myself but am having trouble replicating it at will. I've searched google and the usual places.
Is this a known issue?
WordPress 5.6.5
Thanks for the report.
- Could you provide me with a list of the active plugins on your site please?
- Which version of PHP are you using?
@johnbillion thanks for your quick reply.
PHP Version: 7.4.28
Advanced Custom Fields Advanced Custom Fields: Repeater Field Advanced Order Export For WooCommerce AffiliateWP AffiliateWP - PayPal Payouts Afterpay Gateway for WooCommerce Angell EYE Updater Checkout Address Autocomplete for WooCommerce Custom Order Number Customer Reviews for WooCommerce Duplicate Page Easy Accordion ELEX WooCommerce Australia Post Shipping With Tracking Facebook Chat Plugin - Live Chat Plugin for WordPress Facebook for WooCommerce Geolocation IP Detection GTM4WP Inactive Logout Metrilo for WooCommerce Multi Coupon Tiers Password Protected PixelYourSite Preview E-mails for WooCommerce Print Invoice & Delivery Notes for WooCommerce PW WooCommerce Gift Cards Pro Query Monitor Redirection Test Payment Module for Woocommerce Two Factor Authentication UberMenu 3 - The Ultimate WordPress Mega Menu User Role Editor WC Duplicate Order Widget Context Woo Discount Rules Woo Discount Rules PRO 2.0 WooCommerce WooCommerce Bulk Discount WooCommerce Conditional Shipping and Payments WooCommerce Google Analytics Integration WooCommerce Manual Payment WooCommerce One Page Checkout WooCommerce PickingPal WooCommerce Shipping Per Product v2 WooCommerce Social Login WooCommerce Stripe Gateway WooSidebars WP Affiliate AU Invoice Plugin WP Affiliate Policies Tab WP Cerber Security, Anti-spam & Malware Scan WP Crontrol WP Mail SMTP WP Offload Media Lite WP Rocket WP Rocket | Deactivate WooCommerce Refresh Cart Fragments Cache wpDataTables WPO365 | SAMESITE YITH WooCommerce Featured Video YITH WooCommerce Waiting List Premium Yoast SEO Premium Zip - WooCommerce
This happens for me too. It is not easy to reproduce, because I assume it happens if you are asked to confirm the mail address after the login: /wp-login.php?action=confirm_admin_email
No matching plugins besides Query Monitor.
I'm on a Multisite and on WordPress 5.5.11 (outdated WP could be a reason here maybe?).
PHP version is 7.4.33.
Edit: I think this happens without QM too. QM is just catching the crash in some way, because I see frequently a server error 500 after confirming the mail address. Typing /wp-admin
manually works, so the login was successful.
I've done some debugging of this but I've yet to see how the value passed here to the second parameter of preg_replace()
can be anything except a string. The value is read from the WP::$request
property in WordPress which is only ever set to a string. Its default value is also a string.
I'm going to investigate whether something else in WordPress core sets this property externally. If not, it could be a plugin.
Either of you using any of the plugins listed here? https://wpdirectory.net/search/01GVGWHNGP3GN41V6WXAE8GHEE
No, we don't use any of those plugins.
Hey we have the same problem with Wordpress V5.2.2 and PHP 7.2. We use latest version of query-monitor.
We found that it might have something to do with permalinks? See https://stackoverflow.com/questions/39052581/wordpress-get-error-with-warning-preg-match
2023/05/25 12:22:53 [error] 382#382: *65301 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught TypeError: preg_match() expects parameter 2 to be string, null given in /var/www/wp-content/plugins/query-monitor/collectors/request.php:312
Stack trace:
#0 /var/www/wp-content/plugins/query-monitor/collectors/request.php(312): preg_match('#^app-actions/?...', NULL)
#1 /var/www/wp-content/plugins/query-monitor/classes/Collectors.php(84): QM_Collector_Request->process()
#2 /var/www/wp-content/plugins/query-monitor/classes/Dispatcher.php(108): QM_Collectors->process()
#3 /var/www/wp-content/plugins/query-monitor/dispatchers/Redirect.php(39): QM_Dispatcher->get_outputters('headers')
#4 /var/www/wp-includes/class-wp-hook.php(286): QM_Dispatcher_Redirect->filter_wp_redirect('wp-login.php?lo...', 302)
#5 /var/www/wp-includes/plugin.php(208): WP_Hook->apply_filters('wp-login.php?lo...', Array)
#6 /var/www/wp-includes/pluggable.php(1216): apply_filters('wp_redirect', 'wp-login.php?lo...', 302)
#7 /var/www/wp-includes/pluggable.php(1356): wp_redirect('wp-login.php?lo...', 30" while reading response header from upstream, client: 172.31.7.66, server: _, request: "GET /wp-login.php?action=logout&_wpnonce=0995335a21 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.urlaubsguru.de", referrer: "https://www.urlaubsguru.de/wp-admin/"```
I think this error only occurs on old WP versions pre 6.0 because there what you said doesn't fully apply:
I've done some debugging of this but I've yet to see how the value passed here to the second parameter of
preg_replace()
can be anything except a string. The value is read from theWP::$request
property in WordPress which is only ever set to a string. Its default value is also a string.
In particular the default value wasn't an empty string before this commit:
https://github.com/WordPress/WordPress/commit/a47961e80ee83686e08024eb1ea5e322ed20c739
So I guess what is needed here is a null check or a cast to string.
Oh these are the steps to reproduce this:
- Install Query Monitor on WP 5.9 or older.
- Set the
admin_email_lifespan
to some long ago value, e.g.1688767200
- Login to WP as admin.
You'll now see this Fatal Error.
@kraftner Followed your directions with WP 5.9 on PHP 8.3.8, and I do get a deprecated error, but not a fatal error: is yours a fatal or deprecated?