Closed
Labels
Description
Bug report
A method that returns by reference (function &name()) no longer returns a reference once TypePHP is active, even without any docblock. Writes through the reference are lost and PHP emits a notice.
<?php
final class Bag
{
public array $items = [1];
public function &items(): array
{
return $this->items;
}
}
$bag = new Bag();
$ref = &$bag->items();
$ref[] = 2;
echo json_encode($bag->items), "\n";With TypePHP:
[1]
PHP Notice: Only variable references should be returned by reference in playground.php on line 9
Without TypePHP (TYPEPHP_DISABLE=true): [1,2].
Tested on v0.10.26 and on main (2ec0426).
Code snippet that reproduces the problem
Expected output
[1,2], no notice: the reference returned by items() points to $bag->items, as in plain PHP.
Context: our test suite hits the notice on &getCommandOptions() in our list endpoint base classes. Code that relies on writing through such a reference would silently change behaviour.
Activity
rcalicdan commentedon Oct 3, 2026
This is certainly to be an ast bug in typephp ast transformation parser.. Will look into it..