trigger_error() does not work with E_DEPRECATED.

Created on 23 June 2025, 5 days ago

Problem/Motivation

In some places in core we call trigger_error(***, E_DEPRECATED).
When triggered, this results in:

ValueError: trigger_error(): Argument #2 ($error_level) must be one of E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE, or E_USER_DEPRECATED

core/tests/Drupal/Tests/BrowserTestBase.php
512:    @trigger_error(__METHOD__ . 'is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. There is no direct replacement. See https://www.drupal.org/node/3523039', E_DEPRECATED);

core/tests/Drupal/Tests/PerformanceData.php
341:    @trigger_error(__METHOD__ . 'is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. There is no direct replacement. See https://www.drupal.org/node/3511149', E_DEPRECATED);
368:    @trigger_error(__METHOD__ . 'is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. There is no direct replacement. See https://www.drupal.org/node/3511149', E_DEPRECATED);

core/tests/Drupal/TestTools/ErrorHandler/BootstrapErrorHandler.php
59:    if (E_USER_DEPRECATED === $errorNumber || E_DEPRECATED === $errorNumber) {
66:    if ((E_USER_DEPRECATED === $errorNumber || E_DEPRECATED === $errorNumber) && DeprecationHandler::isIgnoredDeprecation($errorString)) {

core/tests/Drupal/TestTools/ErrorHandler/TestErrorHandler.php
62:    if ((E_USER_DEPRECATED === $errorNumber || E_DEPRECATED === $errorNumber) && DeprecationHandler::isDeprecationTest($this->testCase)) {

core/includes/errors.inc
38:    E_DEPRECATED => ['Deprecated function', RfcLogLevel::DEBUG],

Steps to reproduce

Write a test like this and run it:

use Drupal\Tests\BrowserTestBase;
class MyTest extends BrowserTestBase {
  public function test(): void {
    $this->getOptions('My select');
  }
}

(I think this will reproduce the problem even if 'My select' does not exist.)

Proposed resolution

Replace E_DEPRECATED with E_USER_DEPRECATED.

Find out why this has not popped up in tests before.
Are we not testing these deprecations?

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

11.0 🔥

Component

base system

Created by

🇩🇪Germany donquixote

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024