Open paulgibbs opened 1 year ago
Can confirm we have the same issue. PHP 8.1
Uncaught TypeError: preg_replace(): Argument #3 ($subject) must be of type array|string, bool given
The send_header
inRequestHandler.php
receives a bool at one point: the value is false.
Evaluating $value
in the function, only allowing array|string(or before) stops the fatal error
I'm seeing a similar error on PHP 8.0 (fine on 7.4)
PHP message: PHP Fatal error: Uncaught TypeError: preg_replace(): Argument #3 ($subject) must be of type array|string, bool given in /wordpress/wp-content/plugins/satispress/src/Provider/RequestHandler.php:149"
WARNING: [pool www] child 291 said into stderr: "PHP message: PHP Fatal error: Uncaught TypeError: preg_replace(): Argument #3 ($subject) must be of type array|string, bool given in /wordpress/wp-content/plugins/satispress/src/Provider/RequestHandler.php:149" WARNING: [pool www] child 291 said into stderr: "Stack trace:" WARNING: [pool www] child 291 said into stderr: "#0 /wordpress/wp-content/plugins/satispress/src/Provider/RequestHandler.php(149): preg_replace('/\s+/', ' ', false)" WARNING: [pool www] child 291 said into stderr: "#1 /wordpress/wp-content/plugins/satispress/src/Provider/RequestHandler.php(162): SatisPress\Provider\RequestHandler->send_header('Last-Modified', false)" WARNING: [pool www] child 291 said into stderr: "#2 /wordpress/wp-content/plugins/satispress/src/Provider/RequestHandler.php(102): SatisPress\Provider\RequestHandler->send_headers(Array)" WARNING: [pool www] child 291 said into stderr: "#3 /wordpress/wp-includes/class-wp-hook.php(307): SatisPress\Provider\RequestHandler->dispatch(Object(WP))" WARNING: [pool www] child 291 said into stderr: "#4 /wordpress/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters(NULL, Array)" [error] 192#192: *533 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught TypeError: preg_replace(): Argument #3 ($subject) must be of type array|string, bool given in /wordpress/wp-content/plugins/satispress/src/Provider/RequestHandler.php:149 WARNING: [pool www] child 291 said into stderr: "#5 /wordpress/wp-includes/plugin.php(524): WP_Hook->do_action(Array)" WARNING: [pool www] child 291 said into stderr: "#6 /wordpress/wp-includes/class-wp.php(398): do_action_ref_array('parse_request', Array)" WARNING: [pool www] child 291 said into stderr: "#7 /..."
Stack trace:
Response: HTTP Code: 500 Bytes Sent: 3011 Time: 1.540
This is quite often the case in WordPress. I came across this type of issue recently and stumbled on https://php.watch/versions/8.0/internal-function-exceptions. It may add some complexity to wrap some functions in a try/catch, but it seems to be the only way for now.
@paulgibbs @sdrib @IanRandall There are several related issues pointing to the same line. I believe this should have been taken care of in this commit, though. Can y'all verify you're running the latest version of SatisPress?
RequestHandler::send_header()
is pretty much a direct copy of WP_REST_Server::send_header()
, so any issues are likely due to an incorrect header being sent at some point.
Will take a look, thank you @bradyvercher
maybe use rector? https://github.com/rectorphp/rector
and use LevelSetList::UP_TO_PHP_81
There seems to be a PHP 8 incompatibility, as seen on WP Engine, on PHP 8.0. PHP 7.4 (the only other option they support) works as expected.
Error log output is here https://gist.github.com/paulgibbs/c39a87669114f3b0a5e1343769ddd2e6