Skip to content

ClassType::from() resolves too much interfaces #32

@MCStreetguy

Description

@MCStreetguy

Version: v3.1.2

Bug Description

When "copying" a class through the static factory method ClassType::from(...), it appears that all parent interfaces are applied, not only the ones directly set on the class.

Steps To Reproduce

  1. Create some class that implements interfaces
class Query implements \ArrayAccess, \Countable, \Iterator
{
    # ...
}
  1. Then create a ClassType instance through:
    $class = ClassType::from('MyClass');
  2. Convert it to a string and take a closer look on the result:
class Query implements \ArrayAccess, \Countable, \Iterator, \Traversable
{
    # ...
}

Expected Behavior

The instance of ClassType should be exactly the same as the original one.
Instead, it implements the parental interface Traversable which then leads to an E_COMPILE_ERROR, due to the interface beeing implemented twice:

Class Melior\Database\Query\Query cannot implement previously implemented interface Traversable

Possible Solution

I don't got any handy solution on this, but it seems as ReflectionClass doesn't care about whether something has been defined directly in the class or has been inherited from parents.
So gathering the interfaces from the ReflectionClass results in all interfaces and their parents, not just the ones directly named behind implements.

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