Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
carusogabriel opened this issue Apr 3, 2018 · 5 comments

Comments

@carusogabriel
Copy link
Contributor

carusogabriel commented Apr 3, 2018

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.

@carusogabriel carusogabriel changed the title Comparison operators should not allow string or array in the left sides Comparison operators should not allow string or array in the left side Apr 3, 2018
@Majkl578
Copy link
Contributor

Majkl578 commented Apr 4, 2018

Actually, since we are in strict-rules repo, it should imho only allow int/float and specialized overloaded objects (DateTime{,Immutable}.

@ondrejmirtes
Copy link
Member

ondrejmirtes commented Apr 4, 2018 via email

@Majkl578
Copy link
Contributor

Why was this closed? @ondrejmirtes please reopen, thanks.

@ondrejmirtes ondrejmirtes reopened this Aug 10, 2018
@jasny
Copy link

jasny commented Oct 5, 2018

This doesn't cover the type juggling problem with operators. Loose operators should not be allowed for non-numeric operands at all. See #40

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants