php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #39232 static documentation confuses inheritance and polymorphism
Submitted: 2006-10-23 09:18 UTC Modified: 2007-08-17 13:03 UTC
Votes:2
Avg. Score:2.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: bugs dot php dot net at nanonanonano dot net Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: all
Private report: No CVE-ID: None
 [2006-10-23 09:18 UTC] bugs dot php dot net at nanonanonano dot net
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.)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-17 12:39 UTC] vrana@php.net
No such paragraph on this page now.
 [2007-08-17 13:03 UTC] bugs dot php dot net at nanonanonano dot net
Excellent, thanks!
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Aug 06 22:00:03 2025 UTC