Skip to content

Report PossiblyInvalidPropertyFetch for @property and __get() reads on unions with non-objects - #14706

Merged
orklah merged 3 commits into
vimeo:masterfrom
orklah:pseudo-property-fetch-union
Nov 23, 2026
Merged

orklah merged 3 commits into
vimeo:masterfrom
orklah:pseudo-property-fetch-union

Conversation

@orklah

@orklah orklah commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Reading a @property or a __get() property on a union with a non-object reports InvalidPropertyFetch instead of PossiblyInvalidPropertyFetch, and writing through __set() on such a union adds a PossiblyInvalidMethodCall.

@property / __get() read

Before

<?php
/** @property string $foo */
final class A {
    public function __get(string $n): mixed { return ""; }
}
function f(A|int $a): string { return $a->foo; } // InvalidPropertyFetch

After

function f(A|int $a): string { return $a->foo; } // PossiblyInvalidPropertyFetch

__set() write

Before

<?php
/** @psalm-no-seal-properties */
final class A {
    public function __set(string $n, mixed $v): void {}
}
function f(A|int $a): void { $a->foo = "x"; } // PossiblyInvalidMethodCall, PossiblyInvalidPropertyAssignment

After

function f(A|int $a): void { $a->foo = "x"; } // PossiblyInvalidPropertyAssignment

…-objects

The pseudo-property read is shared between propertyFetchCanBeAnalyzed() and
handleNonExistentProperty(); only the latter marked the fetch as valid, so a
union with a non-object reported InvalidPropertyFetch instead of
PossiblyInvalidPropertyFetch. The fake __set() call is also analysed on the
object part of the receiver only, as the fake __get() call already is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@orklah orklah added the release:fix The PR will be included in 'Fixes' section of the release notes label Nov 23, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T15:03:49.155491Z e833bf8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e833bf8536

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

$context,
$statements_analyzer,
$stmt,
$lhs_type_part,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Join setter side effects across the receiver union

For an A|B receiver of final, unsealed classes whose __set() implementations both write n, with A::$n declared int and B::$n declared ?int, the new per-atomic calls share $context but each MethodCallAnalyzer::analyze() allocates a separate AtomicMethodCallAnalysisResult. Consequently, MethodCallPurityAnalyzer::setPropertyTypeAfterCall() cannot merge the alternatives, and the setter analyzed last replaces $x->n's cached type with int. $x->foo = 1; return $x->n; can then incorrectly satisfy an int return type even though B can return null; previously the cache retained int|null. Merge effects across receiver alternatives instead of applying them sequentially to one context.

Useful? React with 👍 / 👎.

$stmt,
Type::combineUnionTypes($stmt_type, $statements_analyzer->node_data->getType($stmt)),
);
$has_valid_fetch_type = true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Isolate fetch validity for each union alternative

For a receiver A|(B&object{q:int}), where A and non-final B provide __get() and declare @property-read int $foo and @property-read string $foo respectively, setting this shared flag for A makes the intersection loop in analyze() return after inspecting B's object{q:int} member, even though that member has no foo. B's own magic property is never analyzed. A targeted base-versus-commit probe infers int|string before this change but only int afterward, allowing invalid returns or arguments on the B branch to go undetected. Use a local success flag for intersection probing and aggregate it into the union-level validity flag.

Useful? React with 👍 / 👎.

…ccessors

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

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: decreased

Project Memory (MB) Wall (s) Issues Weighted (types) Taint Dead code
✅ laravel 1 772 85.7 25 784 53 058 743 0
✅ symfony 3 619 249.7 $\color{gray}{\textsf{-0.1\%}}$ 51 755 100 583 1 582 0
✅ doctrine-orm 380 14.7 3 458 6 215 0 0
✅ psl 618 19.0 $\color{gray}{\textsf{-1.6\%}}$ 1 390 5 613 1 0
✅ phpunit 456 18.7 $\color{gray}{\textsf{+0.8\%}}$ 1 735 3 418 18 0
✅ php-parser 226 12.4 $\color{gray}{\textsf{-0.1\%}}$ 17 116 21 187 0 0
✅ tempest 898 33.2 $\color{gray}{\textsf{+0.6\%}}$ 5 093 10 567 275 0
✅ amphp-amp 48 1.5 $\color{gray}{\textsf{-0.6\%}}$ 29 49 0 0
✅ webmozarts-assert 273 4.7 575 2 714 0 0
✅ guzzle-promises 46 1.7 $\color{gray}{\textsf{-0.6\%}}$ 156 436 2 0
✅ monolog 136 5.8 $\color{gray}{\textsf{+0.2\%}}$ 918 2 491 11 0
✅ drupal 4 845 235.5 $\color{gray}{\textsf{+0.1\%}}$ 97 854 169 770 575 0
✅ wordpress 2 042 111.6 $\color{gray}{\textsf{-0.7\%}}$ 143 516 $\color{red}{\textsf{+13}}$ $\color{green}{\textsf{-13}}$ 678 151 $\color{green}{\textsf{-39}}$ 461 1
Total 15 358 794.3 $\color{gray}{\textsf{-0.1\%}}$ 349 379 $\color{red}{\textsf{+13}}$ $\color{green}{\textsf{-13}}$ 1 054 252 $\color{green}{\textsf{-39}}$ 3 668 1
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 +10 % 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. Its wall time warns above +5 % (±5 % is noise); the other thresholds apply per project.
  • 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.
✅ wordpress: drift: same issue count, weight changed; issues +13 −13

Memory 2 042 → 2 042 MB (+0.0 %) · Wall 112.3 → 111.6 s (−0.7 %)

Weighted 678 190 → 678 151 (−39, −0.01 %): L3 +13 · L6 −13

Issue type added removed
InvalidPropertyFetch 0 13
PossiblyInvalidPropertyFetch 13 0

Changed in place (13)

@​@​ 13 places @​@​
  src/wp-admin/includes/class-wp-ms-sites-list-table.php:651
  src/wp-includes/Requests/src/Requests.php:798
  src/wp-includes/Requests/src/Session.php:282
  src/wp-includes/class-wp-xmlrpc-server.php:3981
  src/wp-includes/class-wp-xmlrpc-server.php:3982
  src/wp-includes/class-wp-xmlrpc-server.php:3983
  src/wp-includes/pluggable.php:2208
  src/wp-includes/pluggable.php:2210
  src/wp-includes/pluggable.php:2273
  src/wp-includes/pluggable.php:2288
  … and 3 more
- InvalidPropertyFetch:         Cannot fetch property on non-object $_site of type false
+ PossiblyInvalidPropertyFetch: Cannot fetch property on possible non-object $_site of type false

head bbd6abe · base 71a650b (merge-base) · workflow run

…le baseline entries

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@orklah
orklah merged commit 5fa1828 into vimeo:master Nov 23, 2026
159 of 162 checks passed
@orklah
orklah deleted the pseudo-property-fetch-union branch November 23, 2026 18:33
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.

1 participant