Re: inheritance check too strict?

From: Date: Thu, 19 Aug 2010 22:16:41 +0000
Subject: Re: inheritance check too strict?
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-49472@lists.php.net to get a copy of this message
postmaster@colder.ch wrote:
----- "Nathan Rixham" <nrixham@gmail.com> wrote:
class Point2DManager {
     public function distanceBetween( Point2D $p1 , Point2D $p2 ) {};
} class Point3DManager extends Point2DManager {
     public function distanceBetween( Point3D $p1 , Point3D $p2 ) {};
}
This is incorrect. Any class extending Point2DManager should be able to provide at least as much functionality as the parent class. In other words, it should not tighten the pre-conditions. In your case, Point3dmanager will no longer be able to handle 2dpoints, which is a mistake.
lol, got it - confused myself for a bit there! yes agreed.. incorrect: class Parent { function equals(Parent $o) {} } class Child extends Parent { function equals(Child $o) {} } correct: class Parent { function equals(Child $o) {} } class Child extends Parent { function equals(Parent $o) {} } sorry about the noise, nathan

« previous php.internals (#49472) next »