Problem/Motivation

Several classes declare injected services as private or private readonly/protected readonly constructor-promoted properties, but all extend base classes (FormBase, ConfigFormBase, ConfirmFormBase, EntityListBuilder) using core's DependencySerializationTrait. Its __wakeup() reassigns service properties from the parent's scope after unserialization — it can't see private properties at all, and can't reinitialize readonly ones (PHP only allows one-time init from the declaring class's own scope). Result: fatal errors on readonly properties, and silent serialization breakage + PHPStan errors (dependencySerializationTraitProperty.unsupportedPrivateProperty/unsupportedReadOnlyProperty) on private ones.

  Error: Cannot initialize readonly property Drupal\ai_audio_generator\Form\SettingsForm::$entityTypeManager from scope                   
  Drupal\Core\Form\FormBase in Drupal\Core\Form\FormBase->__wakeup()                                                                      

Affected files:

  • Form/SettingsForm.php (fixed here)
  • Form/NodeAudioGenerateForm.php
  • Form/PronunciationDictionaryNodeQuickAddForm.php
  • Form/PronunciationDictionaryPromoteForm.php
  • Form/PronunciationDictionaryQuickAddForm.php
  • Form/PronunciationDictionarySearchForm.php
  • PronunciationDictionaryEntryListBuilder.php

Proposed resolution

Change every affected property from private/private readonly/protected readonly to plain protected:

  -    protected readonly EntityTypeManagerInterface $entityTypeManager,                                                                  
  +    protected EntityTypeManagerInterface $entityTypeManager, 
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

nnevill created an issue. See original summary.

  • nnevill committed fe6b3e8e on 1.0.x
    fix: #3611996 Readonly/private constructor-promoted service properties...
nnevill’s picture

Status: Active » Fixed

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.