You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
jrfnl
changed the title
DisallowedMultipleAssignments false positive when assigning to property of an object in an array
DisallowMultipleAssignments false positive when assigning to variable property of an object in an array
Aug 17, 2024
@GaryJones Thanks for reporting this. I can confirm the issue, which appears to be caused by the variable variable, i.e. the variable for the property name:
$filtered_results[] = $result;
$filtered_results[ $i ] = $result;
$filtered_results->field = $result;
$filtered_results->$field = $result;
$filtered_results[ $i ]->field = $result;
$filtered_results[ $i ]->$field = $result; // <- This is the bug, all other test cases in this code sample are handled correctly.
Describe the bug
False positive on a complex statement that suggests the assignment is not the first block of code.
Try assigning a value to a property of an object contained in an (indexed) array.
Code sample
Custom ruleset
Can be reproduced with the
WordPress-Extra
orSquiz
rulesets, or any combination using theSquiz.PHP.DisallowMultipleAssignments
rule.To reproduce
Steps to reproduce the behavior:
test.php
with the code sample above...phpcs test.php --standard=Squiz --sniffs=Squiz.PHP.DisallowMultipleAssignments -s
or similarExpected behavior
No violation reported.
Versions (please complete the following information)
Additional context
None of the tests seem to have an assignment to a property of an object in an array.
Please confirm
master
branch of PHP_CodeSniffer.The text was updated successfully, but these errors were encountered: