I was reading through the PHP manual and got to the section on constructors.

<snip>

class A {
  function A() {
    echo "I am the constructor of A.<br>\n";
  }

  function B() {
    echo "I am a regular function named B in class A.<br>\n";
    echo "I am not a constructor in A.<br>\n";
  }
}

class B extends A {
  function C() {
    echo "I am a regular function.<br>\n";
  }
}

// This will call B() as a constructor.
$b = new B;




In PHP 3, the function B() in class A will suddenly become a constructor in
class B, although it was never intended to be. The rule in PHP 3 is: 'A
constructor is a function of the same name as the class.'. PHP 3 does not
care if the function is being defined in class B, or if it has been
inherited.

This is fixed in PHP 4 by modifying the rule to: 'A constructor is a
function of the same name as the class it is being defined in.'. Thus in PHP
4, the class B would have no constructor function of its own and the
constructor of the base class would have been called, printing 'I am the
constructor of A.<br>'.
</snip>

It says that when a new class B was made, that the class B would have no
constructor, because the function B() was in the base class. Instead the
class B was supposed to derive it's constructor from class A and output 'I
am the constructor of A.<br>'

When I tried this script, this did not happen and the Function B() was
called as the constructor of class B, even though the function was in the
base class...can anyone help to clear up this matter?????
thanx



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to