Question regarding constructors and child classes

From: Date: Thu, 18 Nov 2004 02:19:01 +0000
Subject: Question regarding constructors and child classes
Groups: php.general 
Request: Send a blank email to php-general+get-202370@lists.php.net to get a copy of this message
If I have the following: <?php class foo { function foo () { echo "constructed!"; } } class childFoo extends foo { function childFoo() { echo "constructed also!"; } } $a = new childFoo(); ?> Is there any way to run both the parent and child constructor? The reason I'm asking this is because in my parent class, the constructor creates the database connection, in the child constructor it set's up all variables for the child class. If I recall, I can do a "parent::constructorname()", is there a way to call the parent's constructor more cleanly, to me , stylewise, it looks funny to have parent::foo(). How would I do this? -Brent

« previous php.general (#202370) next »