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

PHP_MAJOR_VERSION always false comparison #4434

Closed
mvorisek opened this issue Jan 26, 2021 · 12 comments
Closed

PHP_MAJOR_VERSION always false comparison #4434

mvorisek opened this issue Jan 26, 2021 · 12 comments
Labels
Milestone

Comments

@mvorisek
Copy link
Contributor

mvorisek commented Jan 26, 2021

Bug report

PHP_MAJOR_VERSION constant type is weirdly changed by using the constant in strict comparison.

Code snippet that reproduces the problem

https://phpstan.org/r/eb30f898-1007-4cea-9822-ad3cb3a49fa5

Expected output

no error

@ondrejmirtes
Copy link
Member

PHP_MAJOR_VERSION is already one of the dynamicConstantNames (https://phpstan.org/config-reference#constants) so it shouldn't be possible to have this error.

@mvorisek
Copy link
Contributor Author

mvorisek commented Jan 26, 2021

Where it is defined? I am getting the error with the latest phpstan release.

@Kocal
Copy link
Contributor

Kocal commented Jan 26, 2021

@ondrejmirtes
Copy link
Member

Please reproduce that in a minimal repository.

@mvorisek
Copy link
Contributor Author

I already tried to search for that, but I mean where the range is defined.

@ondrejmirtes
Copy link
Member

What range? The constant is always an int: https://phpstan.org/r/23d36685-80b6-4e2c-be0e-0c7632c160b5

@mvorisek
Copy link
Contributor Author

mvorisek commented Jan 26, 2021

I was able to reproduce! Here it is: https://phpstan.org/r/eb30f898-1007-4cea-9822-ad3cb3a49fa5

@ondrejmirtes
Copy link
Member

So weird.

@ondrejmirtes ondrejmirtes reopened this Jan 26, 2021
@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Feb 1, 2021
@ghost
Copy link

ghost commented Feb 19, 2021

I am trying to figure out if my problem is related to this bug. I've got the following code:

	$rc = hash_hmac($algo, $password, $hmac);
	if($rc === false)
		return false;

phpstan reports an error:

Strict comparison using === between string and false will always evaluate to false.

Sure, string and false will always evaluate to false, but the function hash_hmac may return a string or a false, thus my if statement will evaluate the === comparison to true.

 hash_hmac ( string $algo , string $data , string $key , bool $binary = false ) : string|false

Return Values

Returns a string containing the calculated message digest as lowercase hexits unless binary is set to true in which case the raw binary representation of the message digest is returned. Returns false when algo is unknown or is a non-cryptographic hash function.

ref: https://www.php.net/manual/en/function.hash-hmac

@ondrejmirtes
Copy link
Member

@Bill-ColeUS It's not relevant to this issue at all. Open a new issue.

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@42d0b36

@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 Apr 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants