-
Notifications
You must be signed in to change notification settings - Fork 49
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
Comments
Actually, since we are in strict-rules repo, it should imho only allow int/float and specialized overloaded objects (DateTime{,Immutable}. |
hi, good idea, but needs more thinking - what about these types on the
right side? What about other types? What about comparing objects and
scalars?
Maybe some combinations do not work so bad they should be reported by
core...
On Wed, 4 Apr 2018 at 00:56, Gabriel Caruso ***@***.***> wrote:
Inspired by a discussing with @Ocramius <https://github.com/Ocramius>,
@alcaeus <https://github.com/alcaeus>, and @Majkl578
<https://github.com/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:
<?phpvar_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.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#12>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AAGZuM73gYXx_lBLjI4fbN_RIZCBC3lnks5tk_4bgaJpZM4TF6Qa>
.
--
Ondřej Mirtes
|
Why was this closed? @ondrejmirtes please reopen, thanks. |
This doesn't cover the type juggling problem with operators. Loose operators should not be allowed for non-numeric operands at all. See #40 |
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. |
Inspired by a discussing with @Ocramius, @alcaeus, and @Majkl578 today, some comparison operators should not allow an
array
orstring
types on its left side, or it will always result infalse
. Examples: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.
The text was updated successfully, but these errors were encountered: