WordPress.org

Make WordPress Core

Opened 2 weeks ago

Closed 13 days ago

#54453 closed defect (bug) (fixed)

Warning: Undefined array key 0 in /app/news/wp-includes/wp-db.php on line 1323

Reported by: mjaschen Owned by: SergeyBiryukov
Milestone: 5.9 Priority: normal
Severity: normal Version: 5.8.2
Component: Database Keywords: has-patch
Focuses: Cc:

Description

When using $wpdb->prepare() without passing values to ...$args (i.e. preparing a query without bound values), a warning is issued by PHP >= 8.0:

Warning: Undefined array key 0 in /app/news/wp-includes/wp-db.php on line 1323

Reason: it's assumed that at least one value is bound to the query by passing method arguments besides the query string which is not necessarily the case.

The fix: just check if the array contains a value at index 0 before using it.

Attachments (1)

54453.patch (479 bytes) - added by mjaschen 2 weeks ago.
Patch

Download all attachments as: .zip

Change History (4)

@mjaschen
2 weeks ago

Patch

This ticket was mentioned in PR #1900 on WordPress/wordpress-develop by mjaschen.


2 weeks ago

  • Keywords has-patch added

#2 @SergeyBiryukov
13 days ago

  • Milestone changed from Awaiting Review to 5.9

Hi there, welcome to WordPress Trac!

Thanks for the ticket and the PR, this looks good to me.

#3 @SergeyBiryukov
13 days ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 52206:

Database: Check if the $args[0] value exists in wpdb::prepare() before accessing it.

This avoids an Undefined array key 0 PHP warning if no values are passed to the method besides the query string.

Follow-up to [41470].

Props mjaschen.
Fixes #54453.

Note: See TracTickets for help on using tickets.