> But even if he has a constructor in class B, the constructor in class
A still executes as part of the construction of class B, yes?
None of this is what he is observing.
First of all, the answer to the above question is no. If class B has a
constructor, and extends class A (which also has a constructor), then class
A's constructor *will* *not* be called when you create a B object, unless
you either
1) There is no constructor for class B
2) You explicitly call the constructor for A in the constructor for B
Now, what Tim was saying is this:
class Shape {
function Shape () {
echo "I am a shape!";
}
function Square() {
echo "I have sharp corners!";
}
}
class Square extends Shape{
// No constructor defined
}
Now, the class Square does not have constructor, so it inherits the parent
constructor, right? Wrong. It has a constructor, Square::Square(). Doing
$S = new Square();
would result in "I have sharp corners!" being output, but not "I am a
shape!"
NB: I have not actually tested this, I am just explaining what Tim was
saying. And it makes sense, based on what I know of PHP internals, that it
would be this way. In a hard core language, like C++, I doubt it would
behave like this. That is what he is observing.