php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #38081 Change to "resolving static method calls at compile time"
Submitted: 2006-07-12 15:02 UTC Modified: 2006-07-13 17:56 UTC
From: andres at pruna dot com dot ar Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.* OS: *
Private report: No CVE-ID: None
 [2006-07-12 15:02 UTC] andres at pruna dot com dot ar
Description:
------------
In the manual (http://ar2.php.net/manual/en/language.oop5.static.php), is properly documented that: "
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.
"

I'm not arguing if it's correct from OO point of view or not. I say it's a little bit annoying, I don't found any case when this could help, and, instead, there's a lot of requests to change or workaround it (as from comments in this page, in other Feature Requests like 30934, 37052, ...).

In fact, I think that fixing (or "changing") it, would alow to add a new pattern to manual. :)

Anyway, it would help to know what to expect about it.

Reproduce code:
---------------
abstract class Parent {
  static public function doSomething($var) {
    self::howToReallyDoIt($var);
  }
  abstract protected function howToReallyDoIt($var);
}
class Child extends Parent {
  protected function howToReallyDoIt($var) {
    // implementation for Child ...
    echo $var;
  }
}

Child::doSomething('hello');

Expected result:
----------------
hello

Actual result:
--------------
Fatal error: Cannot call abstract method Parent::howToReallyDoIt() in ...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-13 09:52 UTC] helly@php.net
as you said dupe
 [2006-07-13 17:56 UTC] andres at pruna dot com dot ar
Helly, we all understand that it's expected behavoir. However, loosing inheritance in static calls, also make us loose flexibility. Is there any plan to modify this? I can't comment on other bugs, as they are "Bogus", and I can't find any place where you say if it's planned to be changed or not.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 04:01:31 2024 UTC