ID: 22253 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] -Status: Open +Status: Closed Bug Type: Documentation problem Operating System: win2k PHP Version: 4.3.2-dev New Comment:
This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. Old stuff removed, PHP 4 description fixed. Previous Comments: ------------------------------------------------------------------------ [2003-02-24 07:59:38] [EMAIL PROTECTED] Reopening as a doc problem, so doc guys will get this to fix... ------------------------------------------------------------------------ [2003-02-24 02:53:24] [EMAIL PROTECTED] This behavior will not be changed in the context of PHP 4.x, but will be fixed in PHP 5.0 (Zend Engine 2) ------------------------------------------------------------------------ [2003-02-23 17:14:47] [EMAIL PROTECTED] Okay, now I got it. :) The rule for PHP 4 should be: "If class extending a base class hasn't got a constructor of it's own, then the constructor of the base class is called." Your example lacked the constructor for class String itself..but the last example in manual has that special case. And running that example shows that this is bullshit: "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>'." (as it actually calls the method B()!) p.s. Someone should clear out those PHP 3 examples and changes out of the docs altogether as they only cause confusion and only document how it should behave in PHP 4. ------------------------------------------------------------------------ [2003-02-23 05:56:14] [EMAIL PROTECTED] No, no and no. Excerpts: |In PHP 4, a function becomes a constructor, |when it has the same name as the class it |is defined in" In my example, the function printStr is not defined in class printStr, so it should not become a constructor according to this statament. Another example at the bottom of the page you mentioned: |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>'. The above example says, that the B() method becomes a constructor in PHP 3, but *not* in PHP 4, as there is no constructor defined for class B itself. Therefore it inherits the base classes constructor, which exists in the manual's example. In my case, there is no constructor in the base class. Therefore it should not call any method, as the text suggests. So this is not a documented behaviour. In fact it is documented, that it should not work this way in PHP 4, but only in PHP 3... ------------------------------------------------------------------------ [2003-02-23 01:20:05] [EMAIL PROTECTED] It's by design and even documented here: http://www.php.net/manual/en/language.oop.constructor.php ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/22253 -- Edit this bug report at http://bugs.php.net/?id=22253&edit=1