Skip to content

Spreading a variable into a by-reference variadic (a forwarder's ...$vars) passes values, not references. #438

Closed

Description

@blacktrs

Summary

Spreading a variable into a by-reference variadic (a forwarder's ...$vars) passes values, not references.

Repro

<?php
final class Stmt {
    /** @var array<int, mixed> */
    private array $bound = [];
    public function bind(string $types, mixed &...$vars): bool {
        foreach ($vars as $i => &$v) { $v = $types[$i] === 'i' ? $i + 100 : "v$i"; }
        return true;
    }
    public function keep(mixed &...$vars): bool { $this->bound = $vars; return true; }
    public function fill(): void { foreach ($this->bound as $i => &$v) { $v = "f$i"; } }
}
function stmt_bind(Stmt $s, string $types, mixed &...$vars): bool { return $s->bind($types, ...$vars); }
function stmt_keep(Stmt $s, mixed &...$vars): bool { return $s->keep(...$vars); }
$s = new Stmt();
$a = null; $b = 'x';
var_dump(stmt_bind($s, 'is', $a, $b));
var_dump($a, $b);
stmt_keep($s, $a, $b, $c);
$s->fill();
var_dump($a, $b, $c);
function put(&...$x) { foreach ($x as $i => &$v) { $v = "p$i"; } }
$q = [1, 2]; put(...$q); var_dump($q);
$m = [1, 'a']; put(...$m); var_dump($m);
$o = new stdClass; $o->l = ['x', 'y']; put(...$o->l); var_dump($o->l);

Expected (php)

bool(true)
int(100)
string(2) "v1"
string(2) "f0"
string(2) "f1"
string(2) "f2"
array(2) {
  [0]=>
  string(2) "p0"
  [1]=>
  string(2) "p1"
}
array(2) {
  [0]=>
  string(2) "p0"
  [1]=>
  string(2) "p1"
}
array(2) {
  [0]=>
  string(1) "x"
  [1]=>
  string(1) "y"
}

Actual (manticore 1b3f58ac, Darwin arm64)

bool(true)
NULL
string(1) "x"
NULL
string(1) "x"
NULL
array(2) {
  [0]=>
  int(1)
  [1]=>
  int(2)
}
array(2) {
  [0]=>
  int(1)
  [1]=>
  string(1) "a"
}
array(2) {
  [0]=>
  string(1) "x"
  [1]=>
  string(1) "y"
}

Tracking

Known-bug repro: tests/aot/repro/wrong/byref_variadic_forward.php — bash tests/aot/xfail.sh -k byref_variadic_forward 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 24, 2026
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