calling parent class

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!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

calling parent class

Post by shiznatix »

ok i have to call the parent class but its not that easy. heres what i got in one class:

Code: Select all

$tmp = new $ClassName;

return $tmp;
but I can't do:

Code: Select all

parent::__construct();
since that would be that classes parent, not $tmp's classes parent. There is probably some way to write it but I can't seam to find it. I tried

Code: Select all

$tmp->parent::__construct();
but that gave an error of course. any help?
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

create an extra method:

Code: Select all

public function callParentConstruct ()
{
    parent::__construct();
}
or invoke parent::__construct() within the child class' __construct().

:)
Post Reply