Bug #17637: constructors in classes (Back to PHP3)
| From: | Arvid at knast dot dk | Date: | Fri, 07 Jun 2002 09:32:19 +0000 |
| Subject: | Bug #17637: constructors in classes (Back to PHP3) | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-9729@lists.php.net to get a copy of this message | ||
From: Arvid@knast.dk
Operating system: tested on FreeBSD and WinXP
PHP version: 4.2.1
PHP Bug Type: Class/Object related
Bug description: constructors in classes (Back to PHP3)
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 bug report at http://bugs.php.net/?id=17637&edit=1
--
Fixed in CVS: http://bugs.php.net/fix.php?id=17637&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=17637&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=17637&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=17637&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=17637&r=support
Expected behavior: http://bugs.php.net/fix.php?id=17637&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=17637&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=17637&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=17637&r=globals