Currently, I see in Yii following problems if we want to use BaseObject, Component and other base features:
we can not write a framework agnostic code
we can not have own class hierarchy
The solution can be to convert service classes like BaseObject and Component to traits and put them in a separate package.
I analyzed Yii3 sample app, and I doubt that Yii3 going the right way. In my opinion, it breaks the most important (in PHP) principles DRY and KISS. SOLID principles solves problems in compiled languages like Java or C#, and these problems (regid stucture because of type safety) do not exists in PHP. PHP has other problems, too much flexibility and loose typing, and needs other patterns. Some of them are implemented in Yii2, some not invented yet.
My criticism applied actually to wide use of Interfaces in PHP (ID in solid). I believe there should be more traits. Composition considered as better approach then inheritance, but it is undiscovered territory in PHP world, so there are lots of risks also.
I actually would prefer to do less work/typing then more (as I see Yii3 moving to more typing approach). We get better flexibility and testability, but do I need it?
Sometimes but I always can solve it just by coping class hierarhy and change needed part. (we always get PHP source code, what is false for compiled languages - why in my opinion all this SOLID(D) exists)
PHP used mostly for web development, and unit testing in my opinion not so effective there because there is a lot of UI, DB and other external services. I myself prefer functional testing. But for this we do not need all this SOLID(D).
Moreover only since 7.4 we can implement real SOLID (actually D), because PHP before 7.4 does not support covariance and contravariance in Interfaces. But its comming.
Blockquote
I believe there should be more traits. Composition considered as better approach then inheritance, but it is undiscovered territory in PHP world, so there are lots of risks also.
I donβt think traits are mutually exclusive to interfaces.
Traits are for sharing common functionalities:
you can inject Traits in any classes using single inheritance and you can use Interface to regulate what classes must do.
Interface is a what a class must implements(in terms of methods) and not how is implemented.
So both are extremly useful!
Blockquote
I actually would prefer to do less work/typing then more (as I see Yii3 moving to more typing approach). We get better flexibility and testability, but do I need it?
In Yii3 developers tring to use pure interfaces. This is hands down extrimely flexible solution, but when we create our own implementation we need more knowledge and time or we should have simplified original implementation. Old way solution was en abstract class + some interfaces, what I personally used to, but this creates problems in languages with single inheritance.
So probably abstraction with interfaces for flexibility + traits for code inheritance and code re-use would be optimal solution.
Did you have experience with this approach in PHP?