Skip to content

Array cast should emit an error #190

@mvorisek

Description

@mvorisek

Feature Request

Array cast is redundant on array type. (redundant cast emit a phpstan error already)

For scalar type values it wraps the value into an array - inconsistent with casting an array, array is not wrapped again.

For null it produces empty array - can be a mistake in code, scalar type value is wrapped in an array and never empty.

For objects - get_object_vars should be used.

Given these reasons, I would expect phpstan to emit an error if an (array) cast is found.

demo: https://3v4l.org/2INk8

playground: https://phpstan.org/r/e03daaef-49f6-4c30-b029-24bed8f50048 (line 10 should emit an error)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions