Zeev Suraski wrote:
At 17:04 19/08/2010, Ionut G. Stan wrote:

I can't call Child::foo() with an instance of Taz, but I can call Parent::foo() with such an instance. So, I can't use instances of Child wherever instances of Parent would be accepted.

Child should clearly not be allowed to inherit Parent in the code above, since the signature of Child::foo() is more restrictive than the signature of Parent::foo(). The other way around could work (although I don't recall if we allow it):

class Foo {}
class Bar extends Foo {}

class Parent
{
        public function foo(Bar $bar){}
}

class Child extends Parent
{
        public function foo(Foo $foo){}
}


No issues here - since any Bar object is also a Foo object and would pass the is_a validation of Foo. Again, I don't recall if we allow such signature overrides or not.

Zeev

Guys, this is going a bit nuts, let's swap all the Foo and Bar's for a real example - Zeev I've copied the way you specified above.

class Point2D { // Foo
  public $x;
  public $y;
}

class Point3D extends Point2D { // Bar extends Foo
  public $z;
}

class Point2DManager { // Parent
  public function distanceBetween( Point3D $p1 , Point3D $p2 ) {};
}

class Point3DManager extends Point2DManager { // Child extends Parent
  public function distanceBetween( Point2D $p1 , Point2D $p2 ) {};
}

You're saying that makes sense and is no problem? honestly?

Best,

Nathan

ps: no offence / nothing personal just want to get this cleared up

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to