Phil Roberts <ph*****@HOLYflatnetSHIT.net> wrote
in message news:<Xn*************************@206.127.4.22>...
With total disregard for any kind of safety measures nc@iname.com
(Nikolai Chuvakhin) leapt forth and uttered:
Since you defined no constructor for B, new B will simply call
the constructor for A (in PHP 4, at least).
Not strictly true. The parent constructor is not called by default,
it has be called explicitly.
The parent constructor IS called by default, if the child class
has no constructor defined:
...in PHP 4... If a class has no constructor, the constructor
of the base class is being called, if it exists.
http://php.net/manual/en/language.oop.constructor.php
This is really easy to test:
class A {
var $one;
var $two;
function A () {
$this->one = 'String One';
$this->two = 'Sting Two';
}
}
class B extends A {
function show () {
echo 'Field one = ', $this->one, "\r\n";
echo 'Field two = ', $this->two, "\r\n";
}
}
$b = new B();
$b->show();
The above code snippet prints:
Field one = String One
Field two = Sting Two
Cheers,
NC