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

Memcached SASL support is assumed to be always true #6263

Closed
paulbalandan opened this issue Dec 31, 2021 · 10 comments
Closed

Memcached SASL support is assumed to be always true #6263

paulbalandan opened this issue Dec 31, 2021 · 10 comments

Comments

@paulbalandan
Copy link

Bug report

Code snippet that reproduces the problem

Using PHPStan v1.3.0, it assumes that all memcached installations have SASL support.

https://phpstan.org/r/21ec5d0c-0f4e-499c-87ee-9b842a8ce5e6 (using the constant Memcached::HAVE_SASL)
https://phpstan.org/r/ccb205ad-89bb-4af1-b3e9-2330603d3a8e (using the method check on Memcached::setSaslAuthData)

Expected output

Previously on versions before 1.3.0, adding the constant name (Memcached::HAVE_SASL) on the dynamicConstantNames parameter in phpstan.neon clears the error away. However, starting on 1.3.0, the error will become Strict comparison between 0 and false will always evaluate to false. This only happens on machines with ext-memcached installed. On Windows, there's no error. Disabling the RuntimeReflectionProvider does not help either.

For the method_exists error, this is my first time encountering this error in a bid to go away with the constant name but I suppose it also errors.

Did PHPStan help you today? Did it make you happy in any way?

@ondrejmirtes
Copy link
Member

If you have this code:

if (Memcached::HAVE_SASL === 0) {

And you add Memcached::HAVE_SASL to dynamicConstantNames, how can it lead to Strict comparison between 0 and false will always evaluate to false.?

@ondrejmirtes
Copy link
Member

I'll reopen if you clarify what's going on here :)

@paulbalandan
Copy link
Author

I'll try to create a reproducer repo.

@paulbalandan
Copy link
Author

Hi @ondrejmirtes , here is a reproducer, using the actual file (changing only the namespace).
https://github.com/paulbalandan/phpstan-bug6263/runs/5021846840?check_suite_focus=true

This error shows only on ext-memcached enabled machines. On my Windows, where the extension is not available, phpstan reports no errors.

@canvural
Copy link
Contributor

canvural commented Feb 1, 2022

@paulbalandan The type of the constant is bool (https://www.php.net/manual/en/memcached.constants.php) Why are you comparing it to 0?

@ondrejmirtes
Copy link
Member

Oh, that's annoying: https://github.com/JetBrains/phpstorm-stubs/blob/419389d409990c0e4cdd1f5f5c560f0a8ea333d1/memcached/memcached.php#L82

Notice all the constants with boolean in the PHPDoc but with an integer value...

@ondrejmirtes
Copy link
Member

So, what's the actual type that you can check with var_dump?

@paulbalandan
Copy link
Author

I did a bit of tinkering, and it seems all Memcached::HAVE_** constants are really booleans.

php -r "var_dump(class_exists(Memcached::class));"
  php -r "var_dump(Memcached::HAVE_SASL);"
  php -r "var_dump(Memcached::HAVE_JSON);"
  php -r "var_dump(Memcached::HAVE_MSGPACK);"
  php -r "var_dump(Memcached::HAVE_IGBINARY);"
  php -r "var_dump(Memcached::HAVE_SESSION);"
  vendor/bin/phpstan analyse --ansi
  shell: /usr/bin/bash -e {0}
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
Note: Using configuration file /home/runner/work/phpstan-bug6263/phpstan-bug6263/phpstan.neon.dist.
 0/2 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░]   0%
 2/2 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

https://github.com/paulbalandan/phpstan-bug6263/runs/5032025575?check_suite_focus=true

@ondrejmirtes
Copy link
Member

Can you please send PR to jetbrains/phpstorm-stubs that updates these to booleans?

@github-actions
Copy link

github-actions bot commented Mar 6, 2022

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 Mar 6, 2022
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

3 participants