ID: 39048
Updated by: [EMAIL PROTECTED]
Reported By: matti at nitro dot fi
-Status: Open
+Status: Bogus
Bug Type: Scripting Engine problem
Operating System: *
PHP Version: 5.1.6
New Comment:
>In the case of instance class D shouldn't it actually
> print 2 from $D->show() since the method is inherited and
> private static is redefined?
No, I've already explained why.
No bug here.
Previous Comments:
------------------------------------------------------------------------
[2006-10-05 14:56:27] matti at nitro dot fi
Ok. So there must be another way to get static variable than self::$var
to enable inherited methods that use static variables in subclasses?
On the otherhand shouldn't private static be only defined in ongoing
class. In the case of instance class D shouldn't it actually print 2
from $D->show() since the method is inherited and private static is
redefined?
------------------------------------------------------------------------
[2006-10-05 14:32:48] [EMAIL PROTECTED]
"self" (as well as "parent") is resolved in compile time, so it'll
always point to the class where it was used.
This is expected behaviour.
------------------------------------------------------------------------
[2006-10-05 14:21:35] matti at nitro dot fi
Description:
------------
self:: doesn't care for inheritance in instantiated classes.
self:: doesn't care for private.
private & static keywords don't work together.
redeclaration of static variables doesn't work even for private static.
Reproduce code:
---------------
<?php
class A {
static $a = 1;
function show() {
echo self::$a;
}
}
class B extends A {
static $a = 2;
}
B::show(); // writes "1" not "2"
$b = new B();
$b->show(); // writes "1" not "2"
print '<hr />';
class C {
private static $a = 1;
function show() {
echo self::$a;
}
}
class D extends C {
private static $a = 2;
}
D::show(); // writes "1" not "2"
$d = new D();
$d->show(); // writes "1" not "2"
?>
Expected result:
----------------
22<hr />22
Actual result:
--------------
11<hr />11
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=39048&edit=1