Re: Class Extension
| From: | Rowan Tommins [IMSoP] | Date: | Fri, 10 Jul 2026 07:48:17 +0000 |
| Subject: | Re: Class Extension | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-131851@lists.php.net to get a copy of this message | ||
On 10 July 2026 06:02:13 BST, Holly Schilling <holly.a.schilling@outlook.com> wrote:
>The reason I don’t feel the
trait … for syntax is
>appropriate is because of $this. In a function inside a typical
>trait, $this refers to an instance of the trait. In an extension,
>$this refers to an instance of the class being extended.
I don't think that's true - there's no such thing as an "instance of a
trait", the contents of a trait are pasted directly into the class where they're used, and
act just as if they were written inline at that point.
What that does mean is that they have access to private members, which I understand extensions would
not, so that might be a good reason to use a new keyword.
Rowan Tommins
[IMSoP]