Hi,

jvlad schrieb:
Why would this create any problems? Say, you have class B that extends class A and both do define one method and one property under the same names. Will this create a problem? No. It's because there are rules that clearly describe how it works (method and property will be overriden). Similar approach may be applied to trait'ing classes. Why not? For example if you have a property defined above trait'ing, it will be overriden by the trait if it comes up with its own property with the same name (same goes for the properties defined in the ancestor class). If trait defines a property, it can be overriden by class if it introduce it below trait'ing statement. On the other hand, if someone being a developer cares of potential "conflict" (unwanted override), he/she may simply not define properties and constants in the class that's intended to be trait'ed into another class.
This contradicts the idea behind traits.
Here all conflicts are handled explicitly. Overriding is not used between traits to provide greater power and allow the notion of flattening in the way it has been proposed. Your proposal is much like mixins. But mixins have limited composition power caused by this overriding. There are situations without a suitable linearization to get overlapping methods from to different mixins in the needed combination.

The complete argumentation can be found here: http://www.iam.unibe.ch/~scg/Archive/Papers/Duca06bTOPLASTraits.pdf
illustrating the cons of mixins and multiple inheritance.

Kind Regards
Stefan

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

Reply via email to