Skip to content

A override for a trait methods. #9702

@allanmcarvalho

Description

@allanmcarvalho

Description

Sometimes we created a Trait that is used in a lot of class, or only use a trait of a dependency package. I believe that this is so common today at PHP modern projects.

But I see a big opportunity of improvement on this. Today, when we want to implement some code lines before or after a parent class method is very easy, we just to do:

protected function parentMethod(mixed $fooAttribute): mixed
{
    // do something here
    $result = parent::parentMethod($fooAttribute);
    // or do something here
    return $result;
}

I believe that a similar behavior will be very nice on traits, but I don't found a correspondent code to do this with it.

Maybe the right suggestion to do this is:

protected function traitMethod(mixed $fooAttribute): mixed
{
    // do something here
    $result = trait::traitMethod($fooAttribute);
    // or do something here
    return $result;
}

Make sense or it's a bad idea?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions