Error parsing MongoDB 2.0.0 PHP Library
Apache NetBeans version
Apache NetBeans 26 latest release candidate
What happened
Parsing MongoDB 2.0.0 PHP Library incorrectly flags error:
Language / Project Type / NetBeans Component
No response
How to reproduce
- Install MongoDB PHP driver
- Composer require MongoDB PHP Library
- Open project and find errors
Did this work correctly in an earlier version?
No / Don't know
Operating System
NAME="Pop!_OS" VERSION="22.04 LTS" ID=pop ID_LIKE="ubuntu debian"
JDK
openjdk 21.0.6 2025-01-21
Apache NetBeans packaging
Own source build
Anything else
No response
Are you willing to submit a pull request?
No
Is there a real PHP documentation somewhere? The Traits documentation is littered with examples and prosa, but is lacking concrete grammar, so this might or might not be valid syntax. A hint to resolve this would be great.
@matthiasblaesing searching I found this: https://phplang.org/spec/19-grammar.html ,,, e.g.,
https://github.com/php/php-langspec
@jwoehr thanks
The token colour of match stands out to me. Am I right that Query.php has the same construct? I have a feeling this might be getting confused with the support added for match expressions in #2303 ?
@matthiasblaesing I've figured out what is happening with
use Stage\FactoryTrait {
match as private generatedMatch;
}
match here is being interpreted by NetBeans PHP support as the (relatively new) PHP keyword match.
However, in this context, match means the function from FactoryTrait:
public static function match(QueryInterface|array $query): MatchStage
{
return new MatchStage($query);
}
The code is hiding the match function so it can overload the name and use it in the Stage class with a different signature.
MongoDB development team must have named match after the MongoDB aggregation operator it implements named $match (before match became a keyword in PHP). NetBeans PHP support is intepreting the lexeme match as the PHP keyword rather than as an identifier.
Thanks @jwoehr As I said, this looks like it's coming from #2303
cc/ @junichi11 @tmysik to decide whether there's a relevant fix or this should be closed.
Your evaluation seems to be correct. @junichi11, please, would you be able to look into it? Thank you.
Thanks to the team for keeping PHP support in NetBeans relevant. It's my go-to for PHP.
@junichi11 is the only guy we can thank here, without him, the PHP support in NetBeans would be poor.
This is a bug. Thank you for reporting it!
The following example is executable.
<?php
trait ExampleTrait {
public function match() { // class(), trait(), etc. as well
echo "match" . PHP_EOL;
}
}
final class ExampleClass {
use ExampleTrait {
match as private test;
}
public function method() {
$this->test();
}
}
$c = new ExampleClass;
$c->method();
// result
match
I'm still working on PHP 8.4 support. So, I'll try to fix this after that. (maybe, conflict occurs with the parser.)
Related to the Context Sensitive Lexer: https://wiki.php.net/rfc/context_sensitive_lexer