Re: function overriding and class inheritance

From: Date: Tue, 29 May 2007 22:39:14 +0000
Subject: Re: function overriding and class inheritance
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-29903@lists.php.net to get a copy of this message
I'll try get straight to the point: class C1 {} class C2 extends C1 {} abstract class Work1 { public function f1(C1 $c); } class Work2 extends Work1 { public function f1(C2 $c); }
This code violates the LSP (*) - if you have object $X of type C1, you can call $work1->f1($X) but not $work2->f1($X) - so $work2 can't be substituted for $work1. Meaning if you had this code: function foo(Work1 $object) { $X = new C1(); $object->f1($X); } it would break with passing Work2 object into it, which violates the principles of inheritance. (*) http://en.wikipedia.org/wiki/Liskov_substitution_principle -- Stanislav Malyshev, Zend Products Engineer stas@zend.com http://www.zend.com/

« previous php.internals (#29903) next »