Skip to content

MIR1707

ImpureByRefAssignment

An impure function modifies a parameter that was passed by reference, which introduces side effects that can make code harder to reason about and test.

<?php
function updateConfig(array &$config, string $key, mixed $value): void {
$config[$key] = $value; // Modifies caller's array by reference
}

Return a new value instead of modifying by reference, or document the side effect clearly:

<?php
function updateConfig(array $config, string $key, mixed $value): array {
$config[$key] = $value;
return $config;
}
// Usage
$config = updateConfig($config, 'key', 'value');