Re: [RFC:generics]
| From: | Rowan Collins | Date: | Wed, 20 Apr 2016 15:28:54 +0000 |
| Subject: | Re: [RFC:generics] | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-92553@lists.php.net to get a copy of this message | ||
guilhermeblanco@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]