#26930 [Com]: Inheritance of static functions
ID: 26930
Comment by: kell_pt at users dot sf dot net
Reported By: reckert at informationsgesellschaft dot com
Status: Bogus
Bug Type: Zend Engine 2 problem
Operating System: Windows XP
PHP Version: 5CVS-2004-01-16 (dev)
New Comment:
I also filed a bug regarding this problem.
It's not so much a problem as how it works, but how it SHOULD work. It
is counter-intuitive the way inheritance works on static methods, and
should be addressed at least with a mention in the manual.
Previous Comments:
------------------------------------------------------------------------
[2004-05-21 10:17:05] abies@php.net
Dynamic binding has nothing to do with the caller of a
method/function, it is based on the [runtime] class of the
object instance whose method is being called.
Static methods do no operate on object instances, so
dynamic binding is impossible. No compiled OO language
does this. For PHP, it would also break BC.
------------------------------------------------------------------------
[2004-05-21 05:23:42] kell_pt at users dot sf dot net
I beg to differ. If you call b::callInit() and b:: has init()
redefined, it SHOULD call the b::init when refering to self, regardless
of where that "self" is included.
Basically, "self" must take in consideration the caller. This is not
the only hint that the class mechanism is flawed in what concerns to
static methods / properties. Static data and methods should follow the
same concepts from class instances - it's how OOP works - change that
and you can't really claim it's OOP. :)
------------------------------------------------------------------------
[2004-01-16 05:08:56] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
inside callInit self === a
------------------------------------------------------------------------
[2004-01-16 04:58:48] reckert at informationsgesellschaft dot com
Description:
------------
In a static function X a call to another static function in the same
class uses the version of the function in the class where X is
implemented, not the one for which X was called for.
Reproduce code:
---------------
class a {
static function init() {
echo 'a::init()';
}
static function callInit() {
self::init();
// do something important
}
}
class b extends a {
static function init() {
echo 'b::init()';
}
}
b::callInit();
Expected result:
----------------
b::init()
Actual result:
--------------
a::init()
Shouldn't inheritance work the same way as for normal methods?
Thanks for comments,
Ralph
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=26930&edit=1
Thread (5 messages)