WordPress.org

Make WordPress Core

Opened 10 months ago

Closed 5 months ago

Last modified 6 days ago

#52825 closed defect (bug) (fixed)

[PHP 8.1] MySQLi error reporting value changes

Reported by: ayeshrajans Owned by: jrf
Milestone: 5.9 Priority: normal
Severity: normal Version:
Component: Database Keywords: php81 has-patch commit early
Focuses: Cc:

Description

I suppose this is the first ticket for PHP 8.1 - Exciting :)

In PHP 8.1, the default error reporting is set to always throw an exception, as opposed to emitting a warning. WordPress gracefully handles the database errors by inspecting the error codes.

I suggest that WordPress set the error reporting mode to off, which is the default value prior to this change. Unless we do this, any bad MySQLi connection will throw an exception, leading to a WSOD, or a blank page with the uncaught exception error.

(linking to a PR)

Change History (5)

This ticket was mentioned in PR #1099 on WordPress/wordpress-develop by Ayesh.


10 months ago

In PHP 8.1, the default error reporting is set to always throw an exception, as opposed to emitting a warning. WordPress gracefully handles the database errors by inspecting the error codes.

I suggest that WordPress set the error reporting mode to off, which is the default value prior to this change. Unless we do this, any bad MySQLi connection will throw an exception, leading to a WSOD, or a blank page with the uncaught exception error.

Trac ticket: https://core.trac.wordpress.org/ticket/52825

#2 @jrf
5 months ago

  • Keywords commit early added
  • Milestone changed from Awaiting Review to 5.9
  • Owner set to jrf
  • Status changed from new to accepted

This patch is a prerequisite before CI testing against PHP 8.1 can be enabled as the CI build fails in the "Install WordPress" step while running the tools/local-env/scripts/install.js script due to this issue.
Failing build where this can be seen

I've reviewed the patch and this is exactly what needs to be done. Only remark I could make is that the comment should probably use /* .. */ multi-line style 😄
Build without the mysqli error (but still erroring) which includes the PHPUnit patches + this patch

A commit at the earliest convenience would be appreciated. /cc @SergeyBiryukov

#3 @SergeyBiryukov
5 months ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 51582:

Code Modernization: Set the MySQLi error reporting off for PHP 8.1.

Prior to PHP 8.1, the default error handling mode was MYSQLI_REPORT_OFF. An error in the extension, database, query, or the database connection returned false and emitted a PHP warning:

$mysqli = new mysqli("localhost", "non-existing-user", "", "");

Warning: mysqli::__construct(): (HY000/2002): No connection could be made because the target machine actively refused it in ... on line ...

From PHP 8.1 and later, the default error mode is set to MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT. An error in the extension, database, query, or the database connection throws an exception:

$mysqli = new mysqli("localhost", "non-existing-user", "", "");

Fatal error: Uncaught mysqli_sql_exception: Connection refused in ...:...

WordPress has its own error reporting and gracefully handles the database errors by inspecting the error codes. Setting the MySQLi error reporting to off avoids fatal errors due to uncaught exceptions and maintains the current behavior.

References:

Props ayeshrajans, jrf.
Fixes #52825.

This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.


6 days ago

Note: See TracTickets for help on using tickets.