-
Notifications
You must be signed in to change notification settings - Fork 665
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
false is not eliminated when comparing against != "" #10547
Comments
I found these snippets: https://psalm.dev/r/4fb572a4fe<?php
class A {
private ?string $prop = null;
public function __construct() {
if ("" != $env = getenv("TEST")) {
$this->prop = $env;
}
}
}
|
Just using a direct check fixes: https://psalm.dev/r/fb503c39ce Now, a new issue is emitted due to the recently merged #10502, and both in case of the |
I found these snippets: https://psalm.dev/r/fb503c39ce<?php
class A {
private ?string $prop = null;
public function __construct() {
if ($env = getenv("TEST")) {
$this->prop = $env;
}
}
}
|
A direct check would also compare against "0" which would not be intended here. I want just "" and null/false basically. Obviously, writing it out would work, but it's extra verbose and also less efficient code. |
You could just use !empty() If you really need this, give a PR a try |
empty() sadly also compares against |
+++, it along with empty and isset are banned in my codebase (and I'm very thankful for that) I consider this issue as super low priority, I'd rather finish working on #10577 first :) |
A comparison
if ($key != "") { ... }
does still identify $key as beingstring|false
instead of string within the if.https://psalm.dev/r/4fb572a4fe
The goal is being able to simply compare is not empty and not false at once.
Related to #6965.
The text was updated successfully, but these errors were encountered: