Skip to content

Comparison operators should not allow string or array in the left side #12

@carusogabriel

Description

@carusogabriel

Inspired by a discussing with @Ocramius, @alcaeus, and @Majkl578 today, some comparison operators should not allow an array or string types on its left side, or it will always result in false. Examples:

<?php

var_dump('foo' > 4); //bool(false)
var_dump([1, 2, 3] < 2); //bool(false)

I'd like to discuss it before I propose an implementation for it.

Edit: Now PHPStan does detect comparisons between arrays and numbers: https://phpstan.org/r/eaa2bf97-ddb6-4118-a596-49333c7acf7a, which leave us just with the discussion of strings and numbers.

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