Skip to content

Access to internal constant from the same package/class #13041

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

Open
mvorisek opened this issue May 18, 2025 · 6 comments · May be fixed by phpstan/phpstan-src#3998
Open

Access to internal constant from the same package/class #13041

mvorisek opened this issue May 18, 2025 · 6 comments · May be fixed by phpstan/phpstan-src#3998

Comments

@mvorisek
Copy link
Contributor

mvorisek commented May 18, 2025

Bug report

Internal access from the same class/root package should be allowed.

Code snippet that reproduces the problem

https://phpstan.org/r/6e30fb04-d096-42d1-a0b5-7d0672c9c684

Expected output

no error

@VincentLanglet
Copy link
Contributor

I think the issue is that you're missing a namespace
https://phpstan.org/r/241fa8d8-5819-4f1b-9662-2afca4b536f5

@mvorisek
Copy link
Contributor Author

Interesting. I isolated it from code which had namespace...

So in this issue let's focus if the class is the same, with self:: it always is. Root namespace should be computed from the full class name.

@VincentLanglet
Copy link
Contributor

So in this issue let's focus if the class is the same, with self:: it always is. Root namespace should be computed from the full class name.

Not sure to understand. You should give a real example with namespaces then.

@mvorisek
Copy link
Contributor Author

mvorisek commented May 18, 2025

In simple words, https://phpstan.org/r/6e30fb04-d096-42d1-a0b5-7d0672c9c684 (repro from description) should not report any error. The class is not namespaced, but the access is withing the same class, thus internal access is fine.

I mean the NS for computing "root NS" should be computed from the NS incl. class name, ie. "root NS" for the declaration and the access would be "HelloWorld". This only an idea for possible implementation.

@VincentLanglet
Copy link
Contributor

Then does phpstan/phpstan-src#3998 solve your issue ?

@mvorisek
Copy link
Contributor Author

That is exactly perfect, thank you! ❤

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

Successfully merging a pull request may close this issue.

2 participants