Calling methods hasAllTags / hasAnyTag on select queries fails if query has no tag

Created on 7 February 2023, almost 2 years ago

Problem/Motivation

Calling one of the methods hasAllTags or hasAnyTag on select queries throws an error if no tags have been added to the query since the alterTags property is not initialized with an empty array.

Error: Typed property Drupal\Core\Database\Query\Select::$alterTags must not be accessed before initialization in Drupal\Core\Database\Query\Select->hasAnyTag()

Steps to reproduce

Run the following snippet in the codebase:

$query = \Drupal::database()->select('node');
$query->hasAnyTag(['foo', 'bar']);

Proposed resolution

Initialize the alterTags property with an empty array.

Remaining tasks

  • Review patch
  • Write a test (?)
🐛 Bug report
Status

Active

Version

10.1

Component
Database 

Last updated 26 minutes ago

  • Maintained by
  • 🇳🇱Netherlands @daffie
Created by

🇩🇪Germany Patrick R.

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

Comments & Activities

Production build 0.71.5 2024