#28459 [Opn->Ver]: Documentation and Object/class problem
| From: | vrana@php.net | Date: | Thu, 16 Sep 2004 08:13:01 +0000 |
| Subject: | #28459 [Opn->Ver]: Documentation and Object/class problem | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-66266@lists.php.net to get a copy of this message | ||
ID: 28459
Updated by: vrana@php.net
Reported By: alpzrjvr at hotmail dot com
-Status: Open
+Status: Verified
Bug Type: Class/Object related
-Operating System: Slackware 9.0
+Operating System: Slackware 9.0, Windows XP
-PHP Version: 4.3.6
+PHP Version: 4.3.8
Previous Comments:
------------------------------------------------------------------------
[2004-05-20 20:04:59] alpzrjvr at hotmail dot com
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 this bug report at http://bugs.php.net/?id=28459&edit=1