Skip to content

Traits type annotations are not relative to the Trait filename #9

@EmilyShepherd

Description

@EmilyShepherd

Instead they use the filename of the class in which the trait is being used. For example:

src/Some/Directory/ExampleTrait.php:

namespace Some\Directory;

use My/Data/Type;

trait ExampleTrait
{
    /**
     * @param Type $type
     */
    public function testMethod(Type $type)
    {
        return null;
    }
}

src/Other/Directory/ExampleClass.php:

namespace Other\Directory;

class ExampleClass
{
    use ExampleTrait;
}

Using a ReflectionCompositeFactory on ExampleClass raises an Exception because \My\Data\Type is incompatible with \Other\Directory\Type.

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