ID: 17637 Updated by: [EMAIL PROTECTED] Reported By: Arvid at knast dot dk -Status: Analyzed +Status: Closed Bug Type: Class/Object related Operating System: tested on FreeBSD and WinXP PHP Version: 4.2.1 New Comment:
Fixed in PHP 5. Previous Comments: ------------------------------------------------------------------------ [2003-08-10 17:55:08] [EMAIL PROTECTED] PHP 5 modell does this correect. ------------------------------------------------------------------------ [2002-06-07 06:18:18] [EMAIL PROTECTED] OK, the point is that a function is a constructor if it has the same name as the class, regardless it's been defined in another class. Either the docs are wrong or this is a bug. ------------------------------------------------------------------------ [2002-06-07 05:32:18] Arvid at knast dot dk first tjek the links, and you are maybe able to see the bug: http://www.php.net/manual/en/language.oop.constructor.php http://www.bottiger.geeknet.dk/misc/objekt.php if not, i will try to eksplain it, but my english sucks ;) <quote from="http://www.php.net/manual/en/language.oop.constructor.php"> 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>'. </quote> This isn't working in PHP 4.2.1 (or 4.2 i think). When you call the classA is A() a constructor and it prints out 'I am the constructor of A.<br>\n'. That works fine :D But there is a problem by calling ClassB. ClassB extends ClassA, and try listen to the rule one's again: 'constructor is a function of the same name as the class it is being defined in.' There is no function called B() ind ClassB, sp ClassB has NO constructors! In ClassA who extends in ClassB we have to functions, A() and B(). A() is the constructor of ClassA, and should be printed out when we call ClassB, but is dosn't. Instead of printing out A() PHP 4.2.1 has the same bug as PHP3, it prints out B(), and that is the total opposite to what the rule say's ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=17637&edit=1