[meta] Always use named arguments when creating a class instance

Created on 9 June 2021, over 3 years ago
Updated 21 August 2023, about 1 year ago

Problem/Motivation

To be able to reorder class constructor parameters any time, PHP 8 new named arguments feature should be used every time (when "calling a constructor") when creating a class instance.

That would allow more flexible constructor modifications, and eliminate most of the issues when parameter is added/removed/changed. For example problem like "Optional parameter is provided before required" can be fully fixed.

Steps to reproduce

-

Proposed resolution

for example NodeForm.php create function would be:

  public static function create(ContainerInterface $container) {
    return new static(
      entity_repository: $container->get('entity.repository'),
      temp_store_factory: $container->get('tempstore.private'),
      entity_type_bundle_info: $container->get('entity_type.bundle.info'),
      time: $container->get('datetime.time'),
      current_user: $container->get('current_user'),
      date_formatter: $container->get('date.formatter')
    );
  }

Fixing bad parameter names and parameter reordering could be part of the solution (child issues).

Remaining tasks

Create child issues per ?module

User interface changes

None

API changes

Constructors are not part of the API (currently)

Data model changes

-

Release notes snippet

todo

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component
BaseΒ  β†’

Last updated about 17 hours ago

Created by

πŸ‡­πŸ‡ΊHungary pasqualle πŸ‡­πŸ‡Ί Budapest

Live updates comments and jobs are added and updated live.
  • PHP 8.0

    The issue particularly affects sites running on PHP version 8.0.0 or later.

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