netbeans icon indicating copy to clipboard operation
netbeans copied to clipboard

Error parsing MongoDB 2.0.0 PHP Library

Open jwoehr opened this issue 8 months ago • 12 comments

Apache NetBeans version

Apache NetBeans 26 latest release candidate

What happened

Parsing MongoDB 2.0.0 PHP Library incorrectly flags error: Image

Language / Project Type / NetBeans Component

No response

How to reproduce

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

jwoehr avatar Apr 25 '25 22:04 jwoehr

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 avatar Apr 26 '25 12:04 matthiasblaesing

@matthiasblaesing searching I found this: https://phplang.org/spec/19-grammar.html ,,, e.g.,

Image

jwoehr avatar Apr 26 '25 16:04 jwoehr

https://github.com/php/php-langspec

jwoehr avatar Apr 26 '25 16:04 jwoehr

@jwoehr thanks

matthiasblaesing avatar Apr 26 '25 19:04 matthiasblaesing

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 ?

neilcsmith-net avatar Apr 29 '25 08:04 neilcsmith-net

@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.

jwoehr avatar May 12 '25 18:05 jwoehr

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.

neilcsmith-net avatar May 13 '25 09:05 neilcsmith-net

Your evaluation seems to be correct. @junichi11, please, would you be able to look into it? Thank you.

tmysik avatar May 13 '25 14:05 tmysik

Thanks to the team for keeping PHP support in NetBeans relevant. It's my go-to for PHP.

jwoehr avatar May 13 '25 15:05 jwoehr

@junichi11 is the only guy we can thank here, without him, the PHP support in NetBeans would be poor.

tmysik avatar May 13 '25 17:05 tmysik

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.)

junichi11 avatar May 15 '25 14:05 junichi11

Related to the Context Sensitive Lexer: https://wiki.php.net/rfc/context_sensitive_lexer

junichi11 avatar May 15 '25 14:05 junichi11