From:             alpzrjvr at hotmail dot com
Operating system: Slackware 9.0
PHP version:      4.3.6
PHP Bug Type:     Class/Object related
Bug description:  Documentation and Object/class problem

Description:
------------
http://cr2.php.net/language.oop.constructor

PHP manual says: 
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 />'.


But, I test the script in diferent PHP's versions and the result was: 

"I am a regular function named B in class A.
I am not a constructor in A." ... with PHP 4.x.x .

Reproduce code:
---------------
<?
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";
   }
}

$b = new B();
or 
$b = new B; (also works)
?>

Expected result:
----------------
I am the constructor of A.

Actual result:
--------------
I am a regular function named B in class A.
I am not a constructor in A.

-- 
Edit bug report at http://bugs.php.net/?id=28459&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=28459&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=28459&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=28459&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=28459&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=28459&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=28459&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=28459&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=28459&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=28459&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=28459&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=28459&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=28459&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28459&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=28459&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=28459&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=28459&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=28459&r=float

Reply via email to