Problem/Motivation

#3278431: [November 2026] Use PHP 8 constructor property promotion for existing code used a patched rector rule that skips constructor params without a @param tag. This left 207 property assignments in 107 constructors unpromoted. 134 of those params have no constructor docblock.

Steps to reproduce

Proposed resolution

  1. Add the missing @param. Most can be built from the property @var and summary.
  2. Run the rector config from #3278431: [November 2026] Use PHP 8 constructor property promotion for existing code again.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#2 missing-params.txt4.99 KBmstrelan

Issue fork drupal-3635402

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mstrelan created an issue. See original summary.

mstrelan’s picture

StatusFileSize
new4.99 KB

Here's the list of affected classes. Gathered with the help of an LLM.

mstrelan’s picture

Status: Active » Needs review

While rector handled the property promotion, I don't have a script to reproduce the docblock changes, because it wasn't always straightforward to move docs from properties to the constructor docs, particularly if the constructor did not have an existing docblock, so I've let the LLM make all the phpdoc changes before I ran rector. I have reviewed the first 20 classes in the MR and they look correct.

One question before continuing: should we remove the newly added constructor docs that were needed to get rector to work? Or just leave it and remove all constructor docs in bulk in #3565152: [rector] Remove constructor comments.

nicxvan’s picture

Let's remove the comments.

mstrelan’s picture

All of them? Or just ones where there was no previous constructor comment?

For example: core/lib/Drupal/Core/Database/Query/SelectExtender.php previously had no constructor comment, so let's drop it. But what about core/lib/Drupal/Core/Entity/KeyValueStore/Query/QueryFactory.php - should we drop the whole comment or just drop the new @param addition? What about core/lib/Drupal/Core/Extension/ModuleInstaller.php where string $root would have no documentation? Should we limit it to services?

smustgrave’s picture

I thought the new standard was no doc block was needed fore _construct()

mstrelan’s picture

Happy to remove them, they were needed for the rector to work. Just noting the gaps mentioned in #6 where some properties will no longer have any indication of what they are for.

smustgrave’s picture

Just was more generally commenting. Know we’ve been removing a lot of them but not sure if there’s a rule for when to keep.

mstrelan’s picture

I'll remove all of them where they are made up of only services, where they are obvious, and see how that looks. Probably not until next week if anyone wants to jump in first.

catch’s picture

Dropping only the ones that are 100% services sounds good. I think for this issue I'd probably stop there and we can figure the rest out in #3565152: [rector] Remove constructor comments.

smustgrave’s picture

Status: Needs review » Needs work

Sounds like we got a path forward.

mstrelan’s picture

Status: Needs work » Needs review

How does that look now? I didn't drop existing constructor docs, but dropped newly introduced docs that are not needed. So the only new additions should be to properties that are not a service or are not otherwise clear.

quietone’s picture

Title: Add missing @param docs to constructors and promote their properties » Promote properties in constructions and add @param docs where needed

I'd rather we didn't add @params that are not needed. I made some suggestions to remove a few but left others that were the description helped to understand the use of the property.

And I changed the title because 'missing params' implies that params are required for constructors.

mstrelan’s picture

The "missing params" was in order to get the rector to run, but that's no longer relevant. I think in most cases where you've commented on the MR the @param doc is needed to specify the type, unless we go all out and use proper param types here.

nicxvan’s picture

I didn't drop existing constructor docs, but dropped newly introduced docs that are not needed.

Sorry I was so brief, where you ended up is what I meant!

xjm’s picture

mstrelan’s picture

Title: Promote properties in constructions and add @param docs where needed » Promote remaining properties in constructors and add @param docs where needed
smustgrave’s picture

Status: Needs review » Needs work

Would love to see this one land, got a small conflict in core/lib/Drupal/Core/Routing/RouteBuilder.php if that could be fixed please.

mstrelan’s picture

Status: Needs work » Needs review

Resolved the conflict

mondrake’s picture

Status: Needs review » Needs work

AFAIK, if you just assign the constructor argument to the property, even if the property is defined in a parent class, you can still promote in the constructor. Where it won't (necessarily) work is where you call the parent constructor within the child constructor - there you expect the parent constructor to do the assignment to the property. Tried to point the ones that are worth checking again.

godotislate’s picture

I added a couple comments to the MR. I think one thing in general to consider is that if we need a doc comment for a single argument to a constructor that has several arguments, most of them service arguments, instead of adding a constructor docblock that documents every single parameter, we can maybe just document the individual parameter inline. We already do this in several places for Closure arguments: https://git.drupalcode.org/project/drupal/-/blob/main/core/modules/user/..., so it doesn't seem out of place to do it to add typehints. And in PHP 8.6, parameter doc comments are reflectable.

AFAIK, if you just assign the constructor argument to the property, even if the property is defined in a parent class, you can still promote in the constructor.

Not sure we want to promote properties of parent classes in subclass constructors. This makes it a pain to do things like add readonly later, especially if contrib copies the pattern.

mondrake’s picture

#22 documenting only relevant args would be great in general... especially if they are arrays that could get a PHPDoc type. Only thing I think ATM the PHPCS implementation either require all of the args to be documented, or none at all.

Not sure I understand why promoting properties defined in parent classes would be a problem, even specifying readonly: https://3v4l.org/5NP9S#, mind sharing your concern?

godotislate’s picture

Only thing I think ATM the PHPCS implementation either require all of the args to be documented, or none at all.

Yeah, it'd be none at all in the constructor docblock, but inline docs above the parameter as in the example I linked.

Not sure I understand why promoting properties defined in parent classes would be a problem, even specifying readonly: https://3v4l.org/5NP9S#, mind sharing your concern?

It's a BC issue. If the parent does not have readonly now, but we want to add it later, then the child classes need to be updated to match otherwise it will fatal.

godotislate’s picture

Also remembered that in an MR comment for #3486503: Add a file parsing cache collector to replace some uses of FileCache, @catch said this:

If you call the parent constructor you don't have to do property promotion at all - you can just call it and the parent constructor handles that, so I don't think this is something we should go out of our way to support, seems like an anti-pattern to redefine the property promotion.
e.g. subclasses should do:

function construct(?Foo $foo, ?Bar $bar, protected ExtraParameter $extraParameter) {
  parent::construct($foo, $bar);
}
mondrake’s picture

#24, #25, I agree, if we say that properties defined in parents should be defined as promoted properties of the parent constructor, and subclasses' constructors call the parent ones. But that's not the case in several places in this MR; the subclasses directly assign in their constructor the value of the property inherited from the parent. I put a comment inline on one.

mstrelan’s picture

Status: Needs work » Needs review

#21-26: These are all cases that were skipped by rector. Some are properties declared on a parent class or trait, which rector leaves alone to avoid redeclaring them. For the others, rector couldn't resolve the module classes they're typed with. #3278431: [November 2026] Use PHP 8 constructor property promotion for existing code most likely skipped the same cases elsewhere in core, so I'd rather handle them all in a follow-up than by hand here.

mondrake’s picture

Status: Needs review » Reviewed & tested by the community

#27 understand. Let's have a follow-up (meta?) then; leaving code as this is also not a good example for contrib. Some misses are weird, e.g. https://git.drupalcode.org/project/drupal/-/merge_requests/17696#note_64...

catch’s picture

Agreed with a follow-up for the missed property assignment, we can switch from assigning the property to calling the parent without any external change so could happen in any minor release whereas this would still be really good to get into beta.

There are a couple of newly added constructor docblocks with comments on the MR that they're not needed, I'm going to go ahead and push a commit to remove those.

  • catch committed f0659ed9 on 12.0.x
    task: #3635402 Promote remaining properties in constructors and add @...

  • catch committed 0869d3ed on main
    task: #3635402 Promote remaining properties in constructors and add @...
catch’s picture

Version: main » 12.0.x-dev
Status: Reviewed & tested by the community » Fixed

Ah I see we discussed those earlier, but I hadn't realised we'd added them as opposed to not removing them, I think it's OK to remove here they are constructors/services after all. Committed/pushed to main and 12.0.x, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

catch’s picture