Skip to content

fix(php86): report unset, by-reference passing and references of a constant object's property before PHP 8.6 - #14519

Merged
orklah merged 2 commits into
vimeo:masterfrom
jirkace:fix/14500-const-object-write-contexts
Nov 24, 2026
Merged

orklah merged 2 commits into
vimeo:masterfrom
jirkace:fix/14500-const-object-write-contexts

Conversation

@jirkace

@jirkace jirkace commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Unsetting, passing by reference or binding a reference to a property of a constant object is not reported before PHP 8.6, although PHP rejects it at compile time.

Before

<?php
const CONFIG = new stdClass();

unset(CONFIG->debug); // no issue

After

unset(CONFIG->debug); // ParseError: Cannot use temporary expression in write context before PHP 8.6

Fixes #14500

…nstant object's property before PHP 8.6 vimeo#14500

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

jirkace commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Behaviour change

ParseError: Cannot use temporary expression in write context before PHP 8.6 (the check of #14405) is now also reported, when analysing PHP < 8.6, for:

  • unset(C->a), unset(C->a[0]);
  • C->a / C->a[0] passed to a by-reference parameter (m(C->a), sort(C->a));
  • $r = &C->a.

Checked with php -l on PHP 8.5.13: each of these is Fatal error: Cannot use temporary expression in write context; foreach (C->a as &$v) and isset(C->a) are accepted by PHP and stay unreported. Nothing changes for PHP 8.6.

Verified: Php85Test::testInvalidCode@unsetOfAPropertyOfAConstantObjectBeforePhp86, @propertyOfAConstantObjectPassedByReferenceBeforePhp86, @referenceToAPropertyOfAConstantObjectBeforePhp86 fail on master and pass here. Full self-analysis: no new issue (only 2 MixedArgument from my local revolt/event-loop v1.0.9, unrelated).

@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: unchanged

Project Memory (MB) Wall (s) Issues Weighted (types) Taint Dead code
✅ laravel 1 750 58.5 $\color{gray}{\textsf{-0.2\%}}$ 25 908 53 462 682 0
✅ symfony 3 600 263.4 $\color{gray}{\textsf{+1.0\%}}$ 50 611 98 405 1 528 0
✅ doctrine-orm 381 19.4 $\color{gray}{\textsf{-0.9\%}}$ 3 481 6 143 0 0
✅ psl 617 24.4 $\color{gray}{\textsf{-0.9\%}}$ 1 375 5 615 1 0
✅ phpunit 455 14.7 $\color{gray}{\textsf{+0.7\%}}$ 1 731 3 410 18 0
✅ php-parser 226 9.4 $\color{gray}{\textsf{-2.4\%}}$ 17 132 21 025 0 0
✅ tempest 895 26.8 $\color{gray}{\textsf{-1.3\%}}$ 5 047 10 528 252 0
✅ amphp-amp 68 2.0 $\color{gray}{\textsf{+0.5\%}}$ 29 49 0 0
✅ webmozarts-assert 272 4.6 $\color{gray}{\textsf{+0.7\%}}$ 577 2 720 0 0
✅ guzzle-promises 44 1.6 155 434 2 0
✅ monolog 135 5.8 $\color{gray}{\textsf{-4.3\%}}$ 913 2 479 10 0
✅ drupal 4 841 232.4 $\color{gray}{\textsf{-0.7\%}}$ 97 591 169 293 583 0
✅ wordpress 2 041 251.1 $\color{gray}{\textsf{-0.6\%}}$ 142 706 676 686 461 1
Total 15 327 914.0 $\color{gray}{\textsf{-0.2\%}}$ 347 256 1 050 249 3 537 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.

head 60585ea · base c5f4dfd (merge-base) · workflow run

@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! The three cases from #14500 are reported correctly now. A few sibling paths still pass a constant object's property by reference without the check, and PHP 8.5 rejects all of them (Cannot use temporary expression in write context):

<?php
const C = new stdClass();

array_push(C->items, 1);   // no issue
array_unshift(C->items, 1); // no issue
array_splice(C->items, 1);  // no issue
$r = [&C->items];           // no issue
  • array_push/array_unshift/array_splice are handled by ArrayFunctionArgumentsAnalyzer::handleAddition()/handleSplice(), and ArgumentsAnalyzer::analyze() returns before reaching the loop where the check was added, so their first argument should get the check too;
  • a by-reference array item (ArrayAnalyzer, the $item->byRef branch) should call checkConstantObjectWrite() on $item->value.

Could you add these, with a test case for array_push and one for [&C->items], both with 'php_version' => '8.5'?

…reference items on a constant object vimeo#14500

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 24, 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 9d4cbef into vimeo:master Nov 24, 2026
113 of 118 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.

[8.5] Unset, by-reference argument and reference to a property of a constant object not reported below PHP 8.6

2 participants