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

Variables should not be namespaced #8778

Closed
weirdan opened this issue Nov 27, 2022 · 1 comment · Fixed by #8779
Closed

Variables should not be namespaced #8778

weirdan opened this issue Nov 27, 2022 · 1 comment · Fixed by #8779
Labels

Comments

@weirdan
Copy link
Collaborator

weirdan commented Nov 27, 2022

https://psalm.dev/r/0cbef292cd

https://3v4l.org/2qvrC

@weirdan weirdan added the bug label Nov 27, 2022
@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/0cbef292cd
<?php

namespace A {
    $a = 1;
}
namespace B {
    $b = 2;
}
namespace {
    echo $a . PHP_EOL;
    echo $b . PHP_EOL;
}
Psalm output (using commit c3cc906):

INFO: UnusedVariable - 4:5 - $a is never referenced or the value is not used

INFO: UnusedVariable - 7:5 - $b is never referenced or the value is not used

ERROR: UndefinedGlobalVariable - 10:10 - Cannot find referenced variable $a in global scope

INFO: MixedOperand - 10:10 - Left operand cannot be mixed

ERROR: UndefinedGlobalVariable - 11:10 - Cannot find referenced variable $b in global scope

INFO: MixedOperand - 11:10 - Left operand cannot be mixed

weirdan added a commit to weirdan/psalm that referenced this issue Nov 27, 2022
Variables in PHP are not namespaced. In other words, namespaces share
the context with the file they are located in.

See https://3v4l.org/2qvrC

Fixes vimeo#8778
muglug pushed a commit that referenced this issue Nov 27, 2022
Variables in PHP are not namespaced. In other words, namespaces share
the context with the file they are located in.

See https://3v4l.org/2qvrC

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

Successfully merging a pull request may close this issue.

1 participant