Edit report at https://bugs.php.net/bug.php?id=55613&edit=1
ID: 55613 Comment by: g...@php.net Reported by: wil dot moore at wimoore dot com Summary: Feature: Trait checks type of consuming class Status: Open Type: Feature/Change Request Package: Class/Object related Operating System: Mac (Darwin 10.8.0 i386) PHP Version: 5.4.0alpha3 Block user comment: N Private report: N New Comment: So far the community was opposed to 'requiring' interfaces from using classes. However, you can always express 'require' relationships to individual methods by adding them as abstract methods to the trait. >From my point of view that is also the way to go, since traits do not preserve >your invariants, and are meant for code reuse only. Thus, if you imply a certain invariants with an interface, that is not enforced by a trait. A trait can require a certain method to be available since it will be using it, and you might want that to be check at compile time, but a trait does not promise to obey a certain set of requirements on invariants. Please consider using composition and classes if you have strong requirements on how to interact with an object. Previous Comments: ------------------------------------------------------------------------ [2011-09-06 01:10:51] wil dot moore at wimoore dot com Description: ------------ For instance, one may require that the use of a trait "requires" that the consuming class must be of a certain type or implement a specific interface. An example is Doctrine2's ArrayCollection. One may want to write a utility trait that mixes in functionality that is useful to this type of Collection. This trait would work with ArrayCollections or its decedents but would throw an Exception (i.e. TraitConsumerIllegalTypeException) if attempting to use with other types of classes. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=55613&edit=1