Unrelated syntax errors result in ArgumentCountError: Too few arguments to function Drupal\perimeter\EventSubscriber\PerimeterSubscriber::__construct()

Created on 4 July 2023, over 1 year ago
Updated 10 January 2024, 11 months ago

Problem/Motivation

Having any basic PHP syntax error, like missing a bracket in a hook, results in the following error:

ArgumentCountError: Too few arguments to function Drupal\perimeter\EventSubscriber\PerimeterSubscriber::__construct(), 2 passed in /web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 259 and exactly 4 expected in Drupal\perimeter\EventSubscriber\PerimeterSubscriber->__construct() (line 62 of modules/contrib/perimeter/src/EventSubscriber/PerimeterSubscriber.php).

Drupal\perimeter\EventSubscriber\PerimeterSubscriber->__construct() (Line: 259)
Drupal\Component\DependencyInjection\Container->createService() (Line: 177)
Drupal\Component\DependencyInjection\Container->get() (Line: 105)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 224)
Symfony\Component\HttpKernel\HttpKernel->handleThrowable() (Line: 89)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 50)
Drupal\ban\BanMiddleware->handle() (Line: 270)
Drupal\shield\ShieldMiddleware->bypass() (Line: 169)
Drupal\shield\ShieldMiddleware->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 49)
Drupal\remove_http_headers\StackMiddleware\RemoveHttpHeadersMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 704)
Drupal\Core\DrupalKernel->handle() (Line: 19)

This is misleading, and of course instead the regular PHP syntax error should be shown.

No idea why that happens, but I guess it must be due to the early hook we're using and presumably so a required parameter isn't given.

Any ideas?

Steps to reproduce

See abolve. Can this be reproduced in vanilla Drupal 10.1.x with just this module given and a syntax error outside?

Proposed resolution

Remaining tasks

  1. Reproduce in vanilla
  2. Find the root cause
  3. Fix the root cause
  4. Wrte a test (if possible for such case)
  5. Release

User interface changes

None

API changes

None

Data model changes

None

🐛 Bug report
Status

Closed: cannot reproduce

Version

3.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

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

Comments & Activities

Production build 0.71.5 2024