Skip to content

SimplifyEmptyArrayCheck can introduce TypeErrors #9315

@adnweedon

Description

@adnweedon

Bug Report

Subject Details
Rector version 2.0.10
Image

The SimplifyEmptyArrayCheck rule seems to be matching too basic a pattern and just putting whatever contents from empty() before the ===. In this example, the is_array() check ensures that the array_filter() isn't called with a non-array value, because the conditions of the if statement are executed left to right, so by replacing the whole thing with a === any non-array values introduce TypeErrors.

Minimal PHP Code Causing Issue

https://getrector.com/demo/6cd7324e-783f-4e56-ac85-bb7cdfce4bfa

Expected Behaviour

In this case, I think I'd expect it to be skipped?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions