Skip to content

Class resolution fails to check namespace first #299

Description

@markkimsal

Verified on latest main

  • I have confirmed this bug still occurs when built from the latest main branch.

PHPantom version / commit

9092234

Installation method

Built from source

Operating system

Linux x86_64

Editor

VS Code

Bug description

Class resolution checks global namespace before current namespace for sibling classes.

According to:
https://www.php.net/manual/en/language.namespaces.fallback.php

Inside a namespace, an unqualified Name resolves to the current namespace, un-namespaced classes must be accessed with \ specifically

Steps to reproduce

mkdir -p tmp/{src,legacy}

cat <<'EOD' >> tmp/src/A.php
<?php

namespace Src;

class A {
        public static function y(): void {
                B::x();
        }
}
EOD

cat <<'EOD' >> tmp/src/B.php
<?

namespace Src;


class B {
        public static function x(): void {
                echo "x\n";
        }
}
EOD

cat <<'EOD' >> tmp/legacy/B.php 
<?php

class B {

}
EOD

### Error output or panic trace

```text
./target/release/phpantom_lsp analyze tmp/
  3/3 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
 ------ -----------------------------------
  Line   tmp/src/A.php
 ------ -----------------------------------
     7   Method 'x' not found on class 'B'
         🪪  unknown_member
 ------ -----------------------------------


                        
  [ERROR] Found 1 error

.phpantom.toml

Additional context

workaround is to add explicit use Src/B;

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions