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

Unknown symbol mongodb\driver\monitoring\addsubscriber #432

Open
bogdandubyk opened this issue Oct 10, 2023 · 6 comments
Open

Unknown symbol mongodb\driver\monitoring\addsubscriber #432

bogdandubyk opened this issue Oct 10, 2023 · 6 comments

Comments

@bogdandubyk
Copy link

bogdandubyk commented Oct 10, 2023

I have used https://www.php.net/manual/en/function.mongodb.driver.monitoring.addsubscriber.php function in my code, and require checked failing with Unknown symbol mongodb\driver\monitoring\addsubscriber even if I'm adding that function to whitelist like this:

  "symbol-whitelist" : [
    "null", "true", "false",
    "static", "self", "parent",
    "array", "string", "int", "float", "bool", "iterable", "callable", "void", "object",
    "mongodb\\driver\\monitoring\\addsubscriber"
  ],

how can I fix that issue?? Thank you!

The function is imported to class like this:

use function mongodb\driver\monitoring\addsubscriber;

in composer I have

"ext-mongodb": "*",

and

 "mongodb/mongodb": "^1.15",
@fredden
Copy link
Contributor

fredden commented Oct 10, 2023

I have tested this locally. If I have \mongodb\driver\monitoring\addsubscriber(); in my test file, then the described behaviour exists. However, if I instead use \MongoDB\Driver\Monitoring\addSubscriber(); then no error is shown. The only difference I can see here is the case of the functions, and the latter is copied directly from the documentation, so I assume that's the correct version.

This is the output when I remove the ext-mongodb extension from require in composer.json, and have both lines in the test file:

ComposerRequireChecker 4.7.x-dev@a80a012ba94d5423b02754b2816960a74d3d4f3f
The following 2 unknown symbols were found:
+-----------------------------------------+--------------------+
| Unknown Symbol                          | Guessed Dependency |
+-----------------------------------------+--------------------+
| mongodb\driver\monitoring\addsubscriber |                    |
| MongoDB\Driver\Monitoring\addSubscriber | ext-mongodb        |
+-----------------------------------------+--------------------+

This suggests that the problem here is that the case for the intended function is incorrect.

However, the all-lowercase version seems to behave the same for me (in that when I call this without any arguments, it gives the same error). Should composer-require-checker treat classes/functions with unexpected case the same as those with expected case?

Meanwhile, I recommend that @bogdandubyk use the "correct" case for this function.

@maglnet
Copy link
Owner

maglnet commented Oct 10, 2023

Symbols in PHP don't follow consistent casing rules, so functions behave different than variables and constants, afaik.
Regarding this, I'm not sure if trying to work around this issue would be a good idea.

@bogdandubyk
Copy link
Author

hmm, @fredden you are right, and I initially had it like MongoDB\Driver\Monitoring\addSubscriber but changed it into mongodb\driver\monitoring\addsubscriber because of PhpStan error Function mongodb\driver\monitoring\addsubscriber used with incorrect case: MongoDB\Driver\Monitoring\addSubscriber. , so looks like some funny stuff happening between these two tools. Okay then I'll use MongoDB\Driver\Monitoring\addSubscriber to solve require checker issue, and add it to PhpStan baseline so PhpStan will ignore it too

@fredden
Copy link
Contributor

fredden commented Oct 10, 2023

Thanks for the update @bogdandubyk. That sounds like a bug in PHPStan if it's recommending a different case than is used in the documentation. Please can you open an issue with PHPStan about this? Adding it to the baseline seems like a workaround not a fix.

Edit: I've opened phpstan/phpstan#10003 for this.

@Ocramius
Copy link
Collaborator

Possibly wrongg stubs in PHPStan?

@fredden
Copy link
Contributor

fredden commented Oct 10, 2023

The related PHPStan bug has been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants