Req #60107 [Opn->Wfx]: Allow subtype polymorphism in interfaces

From: Date: Sat, 16 Apr 2016 14:10:47 +0000
Subject: Req #60107 [Opn->Wfx]: Allow subtype polymorphism in interfaces
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200597@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60107&edit=1 ID: 60107 Updated by: nikic@php.net Reported by: mkallman at gmail dot com Summary: Allow subtype polymorphism in interfaces -Status: Open +Status: Wont fix Type: Feature/Change Request Package: Unknown/Other Function Operating System: All PHP Version: 5.3.8 Block user comment: N Private report: N New Comment: As dagguh says, this will not be supported as it violates LSP. If anything we'll only allow the reverse. Previous Comments: ------------------------------------------------------------------------ [2011-10-25 09:31:33] dagguh at gmail dot com I disagree, your request violates the LSP. http://en.wikipedia.org/wiki/Liskov_substitution_principle Derived classes cannot expect more than parent class expects. By more I mean a condition that is harder to meet. ------------------------------------------------------------------------ [2011-10-21 11:59:16] mkallman at gmail dot com Description: ------------ Please allow for subtype polymorphism/downcasting in interfaces. Test script: --------------- interface Deliverable {} interface DeliverableWithTruck extends Deliverable {} interface DeliveryService { function deliver( Deliverable $deliverable, $destination ); } class CookieJar implements DeliverableWithTruck {} class ExpressDeliveryService implements DeliveryService { function deliver( DeliverableWithTruck $deliverable, $destination ) { echo "Delivery underway"; } } $fedEx = new ExpressDeliveryService; $chocolateChipCookies = new CookieJar; $fedEx->deliver( $chocolateChipCookies, "Sesame Street" ); Expected result: ---------------- Delivery underway Actual result: -------------- Fatal error: Declaration of ExpressDeliveryService::deliver() must be compatible with that of DeliveryService::deliver() ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=60107&edit=1

« previous php.bugs (#200597) next »