Skip to content

Conditional $container->get() not evaluated correctly #6

Closed
@alcaeus

Description

@alcaeus

First off, is there a way to test the Symfony extension in the PHPStan Playground? In absence of that, here is the classic way of explaining the problem. We have a couple of conditional get calls to the service container like so:

if ($container->has('doctrine.orm.entity_manager')) {
    $em = $container->get('doctrine.orm.entity_manager');
    // ...
}

Unfortunately, this conditional is not properly evaluated:

Service "doctrine.orm.entity_manager" is not registered in the container.

In this case, the get should not cause an error since it will not be reached if there's no such service.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions