Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years 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's profile mjaschen Owned by: sergeybiryukov's profile 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 3 years ago.
Patch

Download all attachments as: .zip

Change History (5)

@mjaschen
3 years ago

Patch

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


3 years ago
#1

  • Keywords has-patch added

#2 @SergeyBiryukov
3 years 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
3 years 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.

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


3 years ago

Note: See TracTickets for help on using tickets.