cedaro / satispress

Expose installed WordPress plugins and themes as Composer packages.
500 stars 48 forks source link

Potential PHP 8.0 incompatibility? #189

Open paulgibbs opened 1 year ago

paulgibbs commented 1 year ago

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

sdrib commented 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

IanRandall commented 1 year ago

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:

0 /wordpress/wp-content/plugins/satispress/src/Provider/RequestHandler.php(149): preg_replace('/\s+/', ' ', false)

1 /wordpress/wp-content/plugins/satispress/src/Provider/RequestHandler.php(162): SatisPress\Provider\RequestHandler->send_header('Last-Modified', false)

2 /wordpress/wp-content/plugins/satispress/src/Provider/RequestHandler.php(102): SatisPress\Provider\RequestHandler->send_headers(Array)

3 /wordpress/wp-includes/class-wp-hook.php(307): SatisPress\Provider\RequestHandler->dispatch(Object(WP))

4 /wordpress/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters(NULL, Array)

5 /wordpress/wp-includes/plugin.php(524): WP_Hook->do_action(Array)

6 /wordpress/wp-includes/class-wp.php(398): do_action_ref_array('parse_request', Array)

Response: HTTP Code: 500 Bytes Sent: 3011 Time: 1.540

thefrosty commented 1 year ago

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.

bradyvercher commented 1 year ago

@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.

IanRandall commented 1 year ago

Will take a look, thank you @bradyvercher

chrillep commented 10 months ago

maybe use rector? https://github.com/rectorphp/rector

and use LevelSetList::UP_TO_PHP_81