From:             bugs dot php dot net at nanonanonano dot net
Operating system: all
PHP version:      Irrelevant
PHP Bug Type:     Documentation problem
Bug description:  static documentation confuses inheritance and polymorphism

Description:
------------
In the fourth paragraph of documentation page:

http://php.net/language.oop5.static

the following appears:

"In fact static method calls are resolved at compile time. When using an
explicit class name the method is already identified completely and no
inheritance rules apply. If the call is done by self then self is
translated to the current class, that is the class the code belongs to.
Here also no inheritance rules apply."

This is incorrect under PHP5 (tested under PHP 5.1.6) -- but I think this
is just a confusion between inheritance and polymorphism in the
documentation.

Static methods and members *are* inherited and can be called through sub
classes (as in the example code on the documentation page in question and
the example given below).

Static methods do not, however, behave polymorphically (there is no
polymorphism in a static call as the caller is being specific about which
version of the function to use and overloaded static functions are not
permitted in PHP).

Reproduce code:
---------------
<?php
class Foo {
   static function a() {
       echo "Foo::a";
   }
}

class Bar extends Foo {
}

Bar::a();



Expected result:
----------------
According to the documentation, "no inheritance rules apply" so it should
give an undefined function error:

"Fatal error: Call to undefined method Bar::a() in /tmp/statictest.php on
line 11"

Actual result:
--------------
Foo::a

(Note: I don't necessarily expect that the documentation will launch into
a long lecture about inheritance and polymorphism in order to clear this
up... but the documentation currently implies that something can't be done
that actually can be done.)

-- 
Edit bug report at http://bugs.php.net/?id=39232&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=39232&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=39232&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=39232&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=39232&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=39232&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=39232&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=39232&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=39232&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=39232&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=39232&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=39232&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=39232&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=39232&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=39232&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=39232&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=39232&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=39232&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=39232&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=39232&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=39232&r=mysqlcfg

Reply via email to