Skip to content

False positive w/ interface_exists ? #188

@SignpostMarv

Description

@SignpostMarv

I'm getting what I think is a false positive when I'm using interface_exists()- I've got an if statement like this:

namespace Foo;

use BarInterface;

class Example
{
    public function exampleFalsePositive(string $classNameThatMightImplementInterfaceBar)
    {
        if (
            interface_exists(BarInterface::class) &&
            is_a($classNameThatMightImplementInterfaceBar, BarInterface::class, true)
        ) {
            foreach ($classNameThatMightImplementInterfaceBar::methodDefinedInBar() as $thing) {
                // do stuff here
            }
        }
    }
}

Now the issue is that in my current environment, interface Bar does not exist, so the fact that was not found should be moot given that I'm checking if it was found with interface_exists().

What I would be expecting is that if a class/interface name was not found but it's used inside an interface_exists() or class_exists call that it should pass in a similar fashion to how calling a method defined in interface A on an object returned from a method whose return type is interface B passes when you wrap the method in an instanceof check.

Thoughts?

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