PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?PHP
class A
{
function A()
{
$this->dosomething();
}
function dosomething()
{
echo "in A<br>";
}
}
class B extends A
{
function B()
{
$this->A(); //will print 'in B'
$this->dosomething(); //will print 'in B'
A::A(); //will print 'in B'
A::dosomething(); //will print 'in A'
}
function dosomething()
{
echo "in B<br>";
}
}
$b = new B;
?>
look at the comment in the constructor of B, i want (if there is a away )
to call the constructor of A from B and still call dosomthing function of A and not B.
can it be done?
Thanks
Guy
Since the constructor in A simply calls the function dosomething() from A, then you can just call this function from B:
A::dosomething();
Since you redefine dosomething() in B, the constructor of A::A() will be calling the B::dosomething(). This is just how inheritance works and there's no real way to get around it.