Hey Holly,

On 08.07.26 12:08, Holly Schilling wrote:
Following the discussion in Discord yesterday, I started working on the feasibility of implementing class extensions. I believe I’ve proven out the concept and viability of it in a 2-phase approach using an extension syntax similar to that of Swift.

Before I go into much more detail, what is the general interest in adding this to the language?


I like how extensions in Swift allow to organise code!

If we ignore implementation details and ownership it's pretty similar to what we have with traits. In PHP, what would be the benefit of extensions over traits? One thing that comes to my mind is that traits can be used by whatever chooses to add it (back to ownership). Good one, but what else? If ownership is the only concern then maybe a small addition to traits could achieve the same?

```
trait Foo
{
    for Baz\Bar::class;  // inverse of "use" to limit usage
}

class Bar
{
    use Foo;
}
```

Brings conflict resolution for free; and I think it would be cheaper than yet another class-like thing. Maybe also feels more php-ish since we already have the trait concept?

Before I go into much more detail, what is the general interest in adding this to the language?

Interested in some sort of solution!

--

Cheers
Nick

Reply via email to