|
|
|
|
|
by troels
5697 days ago
|
|
The difference between mixins and traits is basically that traits happens at compile-time, where mixins are a run time feature. PHP is a bit odd in that it has static object model, where classes are defined as final entities at compile time, then used at run time. Traits hook in at the compile time level. This is unlike most comparable languages (Such as Ruby), where classes are run time constructs. While odd, and somewhat limiting, there is also some benefit to the static object model that PHP has. It gives some point of certainty in a language that is otherwise very dynamic. In general, it leads to easier-to-reason-about code. All with the IMHO disclaimer, understood. |
|
This isn't exactly true. PHP objects can have dynamically assigned members without having magic methods defined. e.g.
And now, with "closures", those members can be methods.