Re: Using a Resource as a Class Property
- From: Michael Fesser <netizen@xxxxxx>
- Date: Sun, 22 Jul 2007 19:59:04 +0200
..oO(Sanders Kaufman)
OK - that seems to be where I went wrong. I thought the base class's
constructor was automatically called when the extended class's was.
Nope.
So, bottom line, what you're saying here is that when you extend a base
class like this, you still have to manually call the base class's
constructor? Zat right?
Correct. PHP doesn't do that automatically, except if the child class
doesn't have a constructor. Then PHP will call the one from the base
class, if it exists. But as soon as your child class uses its own
constructor, you have to manually call the parent one. Usually this
should be the first action.
In PHP 4 you have to use the name of the base class for that (if I
remember that correctly ;-), haven't used PHP 4 since years):
class TFoo extends TBar {
function TFoo {
parent::TBar();
...
}
}
In PHP 5 all constructors have the same name, so it would be just:
class TFoo extends TBar {
public function __construct() {
parent::__construct();
...
}
}
Micha
.
- Follow-Ups:
- Re: Using a Resource as a Class Property
- From: Sanders Kaufman
- Re: Using a Resource as a Class Property
- References:
- Using a Resource as a Class Property
- From: Sanders Kaufman
- Re: Using a Resource as a Class Property
- From: Michael Fesser
- Re: Using a Resource as a Class Property
- From: Sanders Kaufman
- Re: Using a Resource as a Class Property
- From: Michael Fesser
- Re: Using a Resource as a Class Property
- From: Sanders Kaufman
- Re: Using a Resource as a Class Property
- From: Michael Fesser
- Re: Using a Resource as a Class Property
- From: Sanders Kaufman
- Using a Resource as a Class Property
- Prev by Date: Re: Using a Resource as a Class Property
- Next by Date: how to have these two consequent queries become a single one by 'join' in mysql
- Previous by thread: Re: Using a Resource as a Class Property
- Next by thread: Re: Using a Resource as a Class Property
- Index(es):
Relevant Pages
|