On Tue, Jul 11, 2023, at 3:16 PM, Robert Landers wrote:
> On Tue, Jul 11, 2023 at 4:36 PM Larry Garfield <la...@garfieldtech.com> wrote:
>> You have to check your vendor folder for an interface, or trait, or abstract 
>> class.  That doesn't change anything.
>>
>> As noted, now consider a Baz interface.  For interface-and-trait, you add 2 
>> more definitions.  For interface-with-defaults, you add 1.  For abstract 
>> classes, you need to add 4: BazBase, FooBazBase, BarBazBase, and 
>> FooBarBazBase.
>
> I guess I don't understand what the interface is solving if you're
> creating an interface _and_ a trait, why not just create the trait? It
> sounds like you're coupling your interface to a specific
> implementation and trying to get multi-inheritance out of PHP. This
> seems like a design issue, and this RFC seems like a back-way to
> multiple inheritance. Why not just allow multiple inheritance?
>
>> And that's assuming you're even in control of the base classes; you may not 
>> even be able to create all those combinations without lots of copy-pasta.
>>
>> Abstract classes are basically vestigial since PHP 5.4, and have no use 
>> cases:
>
> As a user of abstract classes since the early days of C++, I disagree.
>
> I'd love to see a concrete example, but to me, this just seems like a
> bandaid on an architectural smell.

Real code I wrote a week ago (specifically, for a series of events in a domain 
model):

https://gist.github.com/Crell/f5929e2ee44decd4e9353c41874f26c8

Two different interfaces, that I want to be able to check against, but their 
implementations are trivial.  One of them is used in 2 classes, the other in 3. 
 A base class simply wouldn't work, both because it's semantically incorrect 
(these events are not all "special cases of" some common definition, that's not 
the data model), and because then I couldn't have the class that uses only one 
of them.  Traits, for now, are the best solution, and this is an approach that 
gets taken a lot.

Interface default methods saves a file, and lets us merge the traits into the 
interfaces.  That's basically it.  And that's helpful.

As for it being "back door multi-inheritance", well, Java, Kotlin, and Rust all 
do essentially that now.  So we're hardly breaking new ground, design-wise.  If 
anything, it's playing catch up on data modeling capabilities, an area where 
PHP is still sadly very much lacking.

--Larry Garfield

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

Reply via email to