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

ContainerInterace::has should never return "always true" #668

Open
mglaman opened this issue Nov 29, 2023 · 2 comments
Open

ContainerInterace::has should never return "always true" #668

mglaman opened this issue Nov 29, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@mglaman
Copy link
Owner

mglaman commented Nov 29, 2023

Feature request

Consequence of #610

This caused ContainerInterace::has to be "always true", which may lead developers to removing if ($container->has() checks, causing actual bugs. Especially around conditional dependencies.

Slack thread for context: https://drupal.slack.com/archives/C033S2JUMLJ/p1701250878367139

@mglaman mglaman added the enhancement New feature or request label Nov 29, 2023
@mglaman
Copy link
Owner Author

mglaman commented Mar 22, 2024

Actually, this wasn't a consequence of #610; it's been a latent problem for a while

        if ($methodReflection->getName() === 'has') {
            return new ConstantBooleanType($this->serviceMap->getService($serviceId) instanceof DrupalServiceDefinition);
        }

@mglaman
Copy link
Owner Author

mglaman commented Mar 22, 2024

I think this should be a new bleeding edge toggle to:

  • If the service is provided by core.services.yml, be concrete with the result.
  • If it's from a module, always ensure a null return type
  • If calling get after has, do not consider it to be nullable (maybe if possible?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant