guilhermebla...@gmail.com wrote on 20/04/2016 15:44:
In a given class, I might want to only accept CacheDrivers that also
support BulkOperations. How would I achieve that?
Apologies if this has been refuted elsewhere, but AFAIK you can
implement any intersection constraint, albeit slightly more verbosely,
by creating a new type:
- You can create a new interface that expresses an intersection of two
other interfaces:
interface BulkOperationCacheDriver extends CacheDriver, BulkOperation {}
- Similarly, the intersection of a class and an interface can be created
as an abstract class:
abstact class BulkRedisCacheDriver extends RedisCacheDriver implements
BulkOperation {}
Since you can create those without modifying the underlying classes, you
could specify generic constraints for any given intersection. A union
constraint ("it can be either this or this") cannot currently be
implemented, but the use cases are somewhat more questionable anyway.
Regards,
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php