[php-src] Issue #9702: A override for a trait methods.
| From: | allanmcarvalho | Date: | Mon, 10 Oct 2022 13:35:32 +0000 |
| Subject: | [php-src] Issue #9702: A override for a trait methods. | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-242564@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/9702
Author: 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:
```php
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:
```php
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?