Skip to content

$passes = &$this->$property; $passes[$k][] = $v; (symfony PassConfig::addPass) loses the writes and clobbers the array #199

Closed

Description

@blacktrs

Summary

$passes = &$this->$property; $passes[$k][] = $v; (symfony PassConfig::addPass) loses the writes and clobbers the array.

Repro

<?php
final class PassConfig
{
    public const TYPE_BEFORE_OPTIMIZATION = 'beforeOptimization';
    public const TYPE_REMOVE = 'removing';

    private array $beforeOptimizationPasses = [];
    private array $removingPasses = [];

    public function __construct()
    {
        $this->beforeOptimizationPasses = [100 => [new stdClass()], -1000 => [new ArrayObject()]];
    }

    public function addPass(object $pass, string $type = self::TYPE_BEFORE_OPTIMIZATION, int $priority = 0): void
    {
        $property = $type . 'Passes';
        if (!isset($this->$property)) {
            throw new InvalidArgumentException(sprintf('Invalid type "%s".', $type));
        }
        $passes = &$this->$property;

        if (!isset($passes[$priority])) {
            $passes[$priority] = [];
        }
        $passes[$priority][] = $pass;
    }

    public function counts(): string
    {
        return count($this->beforeOptimizationPasses, COUNT_RECURSIVE) . '/' . count($this->removingPasses, COUNT_RECURSIVE);
    }

    public function all(): array
    {
        $p = $this->beforeOptimizationPasses;
        krsort($p);
        return array_merge(...$p);
    }
}

$c = new PassConfig();
echo $c->counts(), "\n";
$c->addPass(new stdClass());
$c->addPass(new stdClass(), 'beforeOptimization', 200);
$c->addPass(new ArrayObject(), 'removing', -32);
$c->addPass(new stdClass(), 'beforeOptimization', -32);
echo $c->counts(), ' ', count($c->all()), "\n";

Expected (php)

4/0
10/2 5

Actual (manticore bdff2ddf, Darwin arm64)

4/0
0/0 0

Tracking

Known-bug repro: tests/aot/repro/wrong/ref_to_dynamic_property_array_writes_lost.php — bash tests/aot/xfail.sh -k ref_to_dynamic_property_array_writes_lost reports XFAIL while this is open and XPASS once it is fixed; then move the repro into tests/aot/cases/ and close this issue.

Activity

  1. added
    bug
    wrong-answer
    on Oct 11, 2026
  2. added a commit that references this issue on Oct 14, 2026
    dc1d507
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugwrong-answer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions