An overloading question [message #174480] |
Tue, 14 June 2011 16:49 |
sheldonlg
Messages: 166 Registered: September 2010
Karma:
|
Senior Member |
|
|
I have a problem that I am wrestling with that should be so obvious and
easy -- but it isn't. I have a base class that has a method that calls
another method in the base class with $this->thatOtherMethod. I have
another class that extends the base class and I want to have
thatOtherMethod in the extended class override the one in the base
class. The calling method in the base class is called using and
instance of the extended class pointing to that method.
Simply, here is an example:
A.class.php
--------------------------
<?php
abstract class A {
public function b() {
$this->a();
}
protected function a() {
print 'In class A';
}
}
?>
B.class.php
---------------------------
<?php
include_once 'A.class.php';
class B extends A {
public function a() {
print 'In class B';
}
}
?>
c.php
----------------------------
<?php
include 'B.class.php';
$x = new B();
$x->b();
?>
----------------------------
I want it to print out "In class B", but it prints out "In class A".
I have looked over Google quite a bit and found nothing that helped. I
have tried making the methods public, protected, keep them both the same
access, etc. and have had no luck. Suggestions?
--
Shelly
|
|
|