In #3345938: Deprecate support for unused \PDO::FETCH_* modes, we normalized the fetch modes used in Drupal's database operations. However, we fell short of introducing our own logic to indicate the fetch mode, and kept using \PDO::FETCH* constants for the purpose.
Now a new FetchAs enum provides the supported modes. Usage of \PDO::FETCH_* constants in method calls outside of database driver code is deprecated.
The new Drupal\Core\Database\Statement\FetchAs values and the \PDO::FETCH_* constants they are replacing:
| FETCH_* constant | Replace with |
|---|---|
| \PDO::FETCH_ASSOC | Drupal\Core\Database\Statement\FetchAs::Associative |
| \PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE | Drupal\Core\Database\Statement\FetchAs::ClassObject |
| \PDO::FETCH_COLUMN | Drupal\Core\Database\Statement\FetchAs::Column |
| \PDO::FETCH_NUM | Drupal\Core\Database\Statement\FetchAs::List |
| \PDO::FETCH_OBJ | Drupal\Core\Database\Statement\FetchAs::Object |
NOTE: An unintended side-effect of the deprecation assertion logic is to disallow the previously-allowed option to pass a class name as a string to functions like fetchAllAssoc(). Starting in Drupal 11.2, these need to be migrated to a separate call to setFetchMode().