Change record status: 
Project: 
Introduced in branch: 
main
Introduced in version: 
12.0
Description: 

Several \Drupal\Core\Database\Connection methods now carry the PHP 8.5 #[\NoDiscard] attribute:

  • select(), insert(), merge(), upsert(), update(), delete(), truncate()
  • startTransaction()
  • \Drupal\Core\Database\Transaction\TransactionManagerInterface::push()

These methods return a query builder or a Transaction object. Discarding the return value is always a bug: the query is never executed, or the transaction is committed immediately.

On PHP 8.5 and later, ignoring the return value now emits a warning:

The return value of method Drupal\Core\Database\Connection::select() should either be used or intentionally ignored by casting it as (void)

Before (silently did nothing):

  $connection->startTransaction('savepoint_1');

After, to discard a return value on purpose, cast to (void):

  (void) $connection->startTransaction('savepoint_1');

Contributed database drivers that override these methods should add the attribute to their overrides. The core mysql, pgsql, and sqlite drivers already do.

Impacts: 
Module developers