QueryInterface::execute() implementations return string for count queries

Created on 16 April 2022, over 3 years ago
Updated 15 August 2025, 10 days ago

Problem/Motivation

The docblock for QueryInterface::execute() states it returns an int or array; the integer is for count queries. Except, at least on MySQL, it actually returns a string.

This isn't super important in many cases, since PHP is not out of the box type strict, and because we support PHP 7, can't (yet) enforce return or parameter types. This could be fixed on a broader scale in Drupal 10, which will require PHP 8.

This does rear its head in cases when the result is used in type-aware contexts, e.g. on json:api collection counts. If you parse the response in a type-aware language (e.g., TypeScript) this gets stickier.

Steps to reproduce

Run a count query and get a string result instead of an integer.

Proposed resolution

Maybe just wait until we can type all the things in Drupal 10? Or adjust the various implementations to cast the response into an integer if it is_numeric()?

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Closed: duplicate

Version

11.0 πŸ”₯

Component

database system

Created by

πŸ‡ΊπŸ‡ΈUnited States bradjones1 Digital Nomad Life

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024