Le 26/11/2020 à 17:50, David Rodrigues a écrit :
Hello!

Now with PHP 8, traits supports abstract functions that should be
implemented by the class that uses this trait.

So is it now possible that traits could have support to implements too? So
when class uses this trait, it will be an implementation of X interface and
will have to implement methods based on it.

interface A {
     public function x();
}

trait B implements A {
     public function y() { $this->x(); }
     // public function x() still not implemented.
}

class Z { // impliticy implements A interface due to B trait.
     use B;
     public function x() {} // required!
}


Atenciosamente,
David Rodrigues

Hello,

I'd love this too, but I'm not sure what would be the static code validation behavior, knowing that you can rename methods of traits when using them in a class: should the trait method not be validated ? Should the final class be validated after the trait has been used, meaning that if a method name change, the final class must re-implement it ?

--

Pierre

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to