Re: RFC: Trait expects interface
| From: | Rowan Tommins | Date: | Thu, 06 Jan 2022 16:20:41 +0000 |
| Subject: | Re: RFC: Trait expects interface | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-116831@lists.php.net to get a copy of this message | ||
On 6 January 2022 15:21:28 GMT, Robert Korulczyk <robert@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.
* other than "Stringable", whose purpose and implementation continue to baffle me
Regards,
--
Rowan Tommins
[IMSoP]