Skip to content

Remove warning "use statement with non-compound name '...' has no effect" #12949

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
wants to merge 1 commit into
base: PHP-8.3
Choose a base branch
from

Conversation

thg2k
Copy link
Contributor

@thg2k thg2k commented Dec 13, 2023

This message was in fact not true, as the statement indeed has an effect, that is fixing the case for a potential autoloading invocation, as in:

use Alpha;
new alpha();  // will issue autoload for "Alpha" instead of "alpha"

This is very relevant for case-sensitive file systems that load classes using their name as file name.

Moreover, there is not a reason to issue a warning for no-ops, this is a task for static analyzers, not the language itself.

…ect"

This message was in fact not true, as the statement indeed *has* an effect,
that is fixing the case for a potential autoloading invocation, as in:

    use Alpha;
    new alpha();  // will issue autoload for "Alpha" instead of "alpha"

This is very relevant for case-sensitive file systems that load classes
using their name as file name.
@Girgias
Copy link
Member

Girgias commented Dec 16, 2023

Moreover, there is not a reason to issue a warning for no-ops, this is a task for static analyzers, not the language itself.

I very much disagree with this, if the language can do something and warn about errors, then it should. We should not aim to delegate everything to SA, frankly we should do the opposite.

@thg2k
Copy link
Contributor Author

thg2k commented Dec 21, 2023

I very much disagree with this, if the language can do something and warn about errors, then it should. We should not aim to delegate everything to SA, frankly we should do the opposite.

So the PHP engine should raise a warning for situations like:

echo "hello"; "world";

or

if (false) echo "foo";

?

Anyway, this is not what the PR is about, as the use Name; actually does have an effect, so it's about removing a false warning.

@iluuu1994
Copy link
Member

It's true that we generally do not emit warnings even for obvious mistakes. E.g. duplicate switch/match cases. I don't mind dropping this, but maybe send a short message to the ML.

@hakre
Copy link
Contributor

hakre commented Aug 18, 2025

This is very relevant for case-sensitive file systems that load classes using their name as file name.

Depends.

  • The standard PHP auto-load implementation is immune to that - since day one.
  • Your code-base code-style is not portable across file-systems and neither is your project's autoloading. (Bad idea/combination.)

I'd recommend to seek solving the local problem and addressing a better upstream target, instead of removing the diagnostic message that helped you discovering the filename portability issue first of all - by appearing misplaced or wrongworded. @thg2k

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

Successfully merging this pull request may close these issues.

4 participants