On Thu, Jan 6, 2022 at 11:20 AM Rowan Tommins <rowan.coll...@gmail.com>
wrote:

> On 6 January 2022 15:21:28 GMT, Robert Korulczyk <rob...@korulczyk.pl>
> wrote:
> > It should also make it easier for SCA tools to understand
> >the code since they no longer need to know the whole project to
> understand that method from trait is implementation of method from
> interface (which is
> >really tricky right now since it depends on context - trait can at the
> same implement and not implement the interface, because it depends on class
> >where it is used).
>
> Your other points make sense, but I don't think this one does - there are
> no implicit interfaces in PHP*, so all any tool cares about is:
>
> 1) Does the class declaration say that it implements an interface?
> 2) Does it actually contain the methods needed to do so, through any
> combination of direct implementation, inheritance, and trait usage?
>
> Knowing that a particular trait *could be* used to implement a particular
> interface without further code doesn't really tell the tool anything - it
> still has to resolve the list of methods on the class itself, and test
> those against the "implements" clause. This is particularly true if the
> class uses the "as" and "insteadOf" clauses when including the trait, which
> nullify any promises the trait could make.
>
>
> I think the advantage would come within the trait. If I say the trait
expects an interface with two methods, then the tool can act as if the
interfaces methods exist in the trait even if they aren't explicitly
defined. As others have pointed out, though, you can get the same behavior
from declaring the methods not implemented in the trait as abstract.



> * other than "Stringable", whose purpose and implementation continue to
> baffle me
>
> Regards,
>
> --
> Rowan Tommins
> [IMSoP]
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: https://www.php.net/unsub.php
>
>

-- 
Chase Peeler
chasepee...@gmail.com

Reply via email to