Closed
Description
Describe the bug
When arrow function is used together with argument passed as reference (&), phpcs display this error "Expected 1 space after "&" operator; 0 found", which is wrong. if space is incorectly (but as suggested) added then phpcs display this error "Expected 0 spaces after reference operator for argument "$stdClass"; 1 found". phpcbf will simply fail on this. If function is written in old fashion way, everything works correctly.
Code sample
// correct (not considering other sniffs)
var_dump(...array_map(function (?stdClass &$stdClass) {return 1;}, []));
// Expected 1 space after "&" operator; 0 found
var_dump(...array_map(fn (?stdClass &$stdClass) => 1, []));
// 0 spaces after reference operator for argument "$stdClass"; 1 found
var_dump(...array_map(fn (?stdClass & $stdClass) => 1, []));
Custom ruleset
None.
To reproduce
Steps to reproduce the behavior:
- Create a file called
test.php
with the code sample above... - Run
phpcs test.php ...
- See error message displayed
3 | ERROR | [x] Expected 1 space after "&" operator; 0 found
3 | ERROR | [x] Expected 0 spaces after reference operator for argument "$stdClass"; 1 found
Expected behavior
There should be no error displayed with arrow function and zero space between & and paramerer name
Versions (please complete the following information):
- OS: Ubuntu 20.04 LTS
- PHP: PHP 7.4.7
- PHPCS: 3.5.5, master
Additional context
None.