Skip to content

fix(property): an offset write initializes an uninitialized array property - #14358

Merged
orklah merged 4 commits into
vimeo:masterfrom
jirkace:fix/14272-uninit-array-offset-write
Nov 22, 2026
Merged

orklah merged 4 commits into
vimeo:masterfrom
jirkace:fix/14272-uninit-array-offset-write

Conversation

@jirkace

@jirkace jirkace commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Writing an offset of an uninitialized typed array property in the constructor is reported as UninitializedProperty and PropertyNotSetInConstructor, although PHP creates the array on the write.

Before

final class Bag
{
    /** @var array<string, string> */
    private array $values; // PropertyNotSetInConstructor

    public function __construct(string $name)
    {
        $this->values["name"] = $name; // UninitializedProperty
    }
}

After

        $this->values["name"] = $name; // no issue

Fixes #14272

…perty vimeo#14272

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: decreased

Project Memory (MB) Wall (s) Issues Weighted (types) Taint
✅ laravel 1 751 96.4 $\color{gray}{\textsf{-0.2\%}}$ 25 908 53 462 682
✅ symfony 3 600 264.6 $\color{gray}{\textsf{-0.3\%}}$ 50 610 $\color{gray}{\textsf{+0}}$ $\color{green}{\textsf{-1}}$ 98 398 $\color{green}{\textsf{-7}}$ 1 528
✅ doctrine-orm 381 13.3 $\color{gray}{\textsf{+0.7\%}}$ 3 481 6 143 0
✅ psl 617 17.9 $\color{gray}{\textsf{+0.3\%}}$ 1 375 5 615 1
✅ phpunit 455 14.2 $\color{gray}{\textsf{-1.3\%}}$ 1 731 3 410 18
✅ php-parser 226 9.4 $\color{gray}{\textsf{+0.3\%}}$ 17 132 21 025 0
✅ tempest 895 26.9 $\color{gray}{\textsf{-0.3\%}}$ 5 047 10 528 252
✅ amphp-amp 68 1.5 $\color{gray}{\textsf{-0.7\%}}$ 29 49 0
✅ webmozarts-assert 273 3.5 $\color{gray}{\textsf{+1.2\%}}$ 577 2 720 0
✅ guzzle-promises 44 1.2 $\color{gray}{\textsf{+0.8\%}}$ 155 434 2
✅ monolog 135 4.2 $\color{gray}{\textsf{+1.0\%}}$ 913 2 479 10
✅ drupal 4 841 193.6 $\color{gray}{\textsf{+1.7\%}}$ 97 580 $\color{gray}{\textsf{+0}}$ $\color{green}{\textsf{-11}}$ 169 236 $\color{green}{\textsf{-57}}$ 583
Total 13 286 646.5 $\color{gray}{\textsf{+0.3\%}}$ 204 538 $\color{gray}{\textsf{+0}}$ $\color{green}{\textsf{-12}}$ 373 499 $\color{green}{\textsf{-64}}$ 3 076
How to read this table
  • Memory: Psalm's own peak figure, threads=1. More than +5 % fails, unless the PR changes composer.json.
  • Wall: base and head run on the same runner; ±10 % is noise. Above +20 % warns, never fails. re-run: a reversed second run was taken and the faster kept.
  • Issues: head count over all categories, then $\color{red}{\textsf{+added}}$ $\color{green}{\textsf{-removed}}$ against base.
  • Weighted (types): type issues weighted by error level (levels 1–8 as is, always-errors 10, strictness checks 1). Taint and dead-code issues are not weighed. The projects' own code is pinned and their dependencies resolve identically for base and head, so a change means Psalm reports more, fewer or differently serious issues. A rise is not necessarily a regression.
  • Taint: head count of Tainted* issues, then $\color{orange}{\textsf{+added}}$ $\color{orange}{\textsf{-removed}}$ against base. Both are orange as either direction needs review: more can be new detection or false positives, fewer can be fixed false positives or lost detection.
  • Dead code: head count of unused-code issues, shown only when a run reported some (findUnusedCode). More is red, fewer is green.
  • Total: sum over the projects compared on both sides. Thresholds apply per project, not to the total.
  • Colors: $\color{red}{\textsf{red}}$ past a fail or warn threshold (or more issues), $\color{green}{\textsf{green}}$ an improvement past noise (or fewer issues), $\color{orange}{\textsf{orange}}$ needs review, $\color{gray}{\textsf{gray}}$ noise.
  • Performance: regressed if a head run crashed or timed out or a memory or wall delta is red, else improved if one is green, else unchanged. Its icon is the check result: ❌ fail · ⚠️ warn · ✅ pass; the icon next to each project is that project's result, 💥 = not comparable: base crashed or timed out (counts as ⚠️).
  • Types (heading): direction of the total weighted change, increased · decreased · unchanged. Taint and Dead code (heading): added and removed counts, present only when non-zero. Informational, never fails the check.
✅ symfony: issues +0 −1

Memory 3 600 → 3 600 MB (<0.1 %) · Wall 265.4 → 264.6 s (−0.3 %)

Weighted 98 405 → 98 398 (−7, −0.01 %): L7 −1

Issue type added removed
UninitializedProperty 0 1

Removed (1)

  • src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Configuration.php:84 UninitializedProperty (error): Cannot use uninitialized property $this->thresholds
✅ drupal: issues +0 −11

Memory 4 841 → 4 841 MB (<0.1 %) · Wall 190.4 → 193.6 s (+1.7 %)

Weighted 169 293 → 169 236 (−57, −0.03 %): L2 −4 · L7 −7

Issue type added removed
PropertyNotSetInConstructor 0 4
UninitializedProperty 0 7

Removed (11)

  • core/lib/Drupal/Core/Config/ConfigImporter.php:219 UninitializedProperty (error): Cannot use uninitialized property $this->processedConfiguration
  • core/lib/Drupal/Core/Config/ConfigInstaller.php:101 UninitializedProperty (error): Cannot use uninitialized property $this->activeStorages
  • core/lib/Drupal/Core/Config/ConfigInstaller.php:30 PropertyNotSetInConstructor (error): Property Drupal\Core\Config\ConfigInstaller::$activeStorages is not defined in constructor of Drupal\Core\Config\ConfigInstaller or in any methods called in the constructor
  • core/lib/Drupal/Core/Config/StorageComparer.php:137 UninitializedProperty (error): Cannot use uninitialized property $this->changelist
  • core/lib/Drupal/Core/Config/StorageComparer.php:57 PropertyNotSetInConstructor (error): Property Drupal\Core\Config\StorageComparer::$changelist is not defined in constructor of Drupal\Core\Config\StorageComparer or in any methods called in the constructor
  • core/lib/Drupal/Core/Extension/ExtensionPathResolver.php:18 PropertyNotSetInConstructor (error): Property Drupal\Core\Extension\ExtensionPathResolver::$extensionLists is not defined in constructor of Drupal\Core\Extension\ExtensionPathResolver or in any methods called in the constructor
  • core/lib/Drupal/Core/Extension/ExtensionPathResolver.php:33 UninitializedProperty (error): Cannot use uninitialized property $this->extensionLists
  • core/lib/Drupal/Core/Extension/ExtensionPathResolver.php:34 UninitializedProperty (error): Cannot use uninitialized property $this->extensionLists
  • core/lib/Drupal/Core/Extension/ExtensionPathResolver.php:35 UninitializedProperty (error): Cannot use uninitialized property $this->extensionLists
  • core/lib/Drupal/Core/Extension/ExtensionPathResolver.php:36 UninitializedProperty (error): Cannot use uninitialized property $this->extensionLists
  • … and 1 more

head d6885a7 · base 3a3fdf6 (merge-base) · workflow run

# Conflicts:
#	tests/PropertyTypeTest.php

@orklah orklah left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The offset write is now accepted in the constructor, but the exemption also covers native
readonly properties, where PHP throws instead of creating the array:

final class Bag
{
    /** @var array<string, string> */
    public readonly array $values;

    public function __construct(string $name)
    {
        $this->values["name"] = $name; // Error: Cannot indirectly modify readonly property Bag::$values
    }
}

master reports UninitializedProperty + PropertyNotSetInConstructor here; this PR reports nothing (same
with a readonly class). Excluding natively readonly properties fixes it:

|| ($in_assignment
    && $stmt_type->isArray()
    && $codebase->properties->hasStorage($property_id)
    && !$codebase->properties->getStorage($property_id)->native_readonly
)

Could you add that, with this case to providerInvalidCodeParse:

'offsetWriteToAnUninitializedReadonlyArrayProperty' => [
    'code' => '<?php
        final class Bag
        {
            /** @var array<string, string> */
            public readonly array $values;

            public function __construct(string $name)
            {
                $this->values["name"] = $name;
            }
        }',
    'error_message' => 'UninitializedProperty',
    'error_levels' => [],
    'php_version' => '8.1',
],

and, to pin the boundaries, valid cases for $this->values[] = $x; and $this->values["a"]["b"] = $x;,
plus an invalid case for $this->values["a"] .= "x"; (a read-modify-write, which PHP rejects on an
uninitialized property)?

jirkace and others added 2 commits November 21, 2026 17:08
…roperty

PHP throws for an offset write to an uninitialized native readonly property instead of
creating the array, so the exemption of an uninitialized array property leaves those out.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@jirkace

jirkace commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Pushed d6885a7. The exemption leaves natively readonly properties out (!native_readonly, as you wrote it). Cases: offsetWriteToAnUninitializedReadonlyArrayProperty (yours) and the same for a readonly class, both failing on the previous head (nothing reported); valid $this->items[] = $x; and $this->nested["a"]["b"] = $x;; and compoundOffsetWriteToAnUninitializedArrayProperty ($this->values["a"] .= "x"), which is reported as UninitializedProperty on both heads, so a guard. @orklah

@orklah orklah added the release:fix The PR will be included in 'Fixes' section of the release notes label Nov 22, 2026

@orklah orklah left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jirkace!

@orklah
orklah merged commit 6dad94d into vimeo:master Nov 22, 2026
71 of 72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:fix The PR will be included in 'Fixes' section of the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Writing an offset into an uninitialized typed array property is reported as UninitializedProperty

2 participants