Phpinspectionsea: FP: The parameter is overridden immediately (original value is lost)

Created on 14 May 2019  路  11Comments  路  Source: kalessil/phpinspectionsea


| Subject | Details |
| :------------- | :---------------------------------------------------------------------------- |
| Plugin | Php Inspections (EA Extended) |
| Language level | PHP 7.1 |

Current behaviour

Throw a false positive error

Expected behaviour

Nothing

Environment details

How to reproduce:

$validationErrors = [];
if (count($validationErrors)) {}
question

Most helpful comment

@florianajir: updated!

All 11 comments

Hi,

I can't reproduce the issue with your example.

Could you give further details or a larger example who could show the issue?

Thank you for reporting @florianajir, I also could not reproduce. Would you please share an extended code fragment, please?

It seems to be an ide init bug or I don't know what but the error did not thrown today.
However that was not the first time I seen this false positive error.

But you can close the issue because I'm not able to reproduce anymore.

Ok, it would be great to get a reproducible sample if you run into the issue again. meanwhile closing,

It happens again

image

image

I can see now, looks like a correctly reported case: $validationErrors is overridden and not being used between the declaration and the override. In this case, renaming the local variable is recommended.

$validationErrors is a parameter of your method. You change its value without using it once. That's why Kalessil recommanded to use a different name for your variable, to avoid confusion between the value passed in parameter and the changed value.

Ok I didn't notice the parameter of the method, my bad. Thank you!

@florianajir, just a second =) I'm thinking if warning message needs to be adjusted, perhaps you can propose how it can be improved?

Indeed reading the message i supposed the problem come after the declaration.
Maybe something like "This variable name has already been declared previously without being used"

@florianajir: updated!

Was this page helpful?
0 / 5 - 0 ratings