Code Inspection: Array write access is not used
Configure inspections: Settings | Editor | Inspections
Show intention actions: AltEnter
Reports the array write access expressions that are not used in code afterwards. The most common source of such problems is modifying an array passed via a parameter: if an array is passed by value, the change will not be visible outside the function.
In the following example, the modifyArray()
function is intended to modify the array passed as a parameter. Initially, the $myArr
array parameter is passed by value, so modifying it will not have any effect outside the function. After the quick-fix is applied, the reference sign &
is added to the parameter in the function declaration, which means that the array parameter is passed by reference and will therefore be modified is intended.
Before the quick-fix
function modifyArray(array $myArr) { $myArr['key'] = 'value';}
After the quick-fix
function modifyArray(array &$myArr) { $myArr['key'] = 'value';}
Place the caret at the highlighted line and press AltEnter or click
.
Click the arrow next to the inspection you want to suppress and select the necessary suppress action.