php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #34703 late binding for static calls
Submitted: 2005-10-02 00:16 UTC Modified: 2005-10-03 11:14 UTC
Votes:5
Avg. Score:4.8 ± 0.4
Reproduced:3 of 4 (75.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
From: pornel at despammed dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.1.0RC1 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: pornel at despammed dot com
New email:
PHP Version: OS:

 

 [2005-10-02 00:16 UTC] pornel at despammed dot com
Description:
------------
In PHP it is not possible to write base class for singleton and similar programming patterns.

I know it is intended behavior and backwards compatibility may make changes difficult, but there is significant number of complaints about current implementation:
http://bugs.php.net/bug.php?id=30235
http://bugs.php.net/bug.php?id=30934
http://bugs.php.net/bug.php?id=30423
http://bugs.php.net/bug.php?id=19376
http://bugs.php.net/bug.php?id=26930
http://bugs.php.net/bug.php?id=28442
http://bugs.php.net/bug.php?id=29647

and I'd like to add another one.

I'm trying to write functionality that works similar to ActiveRow implementation in RubyOnRails, but the way in which PHP handles static methods and inheritance makes such implementation impossible.

I hope you could implement late binding for static calls and fields. 

It could be used with this:: construct instead of self::, which may be emulated for backwards compatiblity.


Reproduce code:
---------------
class Base
{
  static function test1() {self::test2();}
  static function test2() {echo 'failure';}
}

class Child
{
  static function test2() {echo 'success';}
}

Child::test();


Expected result:
----------------
success

Actual result:
--------------
failure


backtrace doesn't contain reference to Child class (that would be enough for a workaround).


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-02 00:18 UTC] pornel at despammed dot com
Ooops, code example should have "class Child extends Base" and "Child::test1()", ofcourse.
 [2005-10-02 13:16 UTC] kowalski-kamil at wp dot pl
How do you want to use Base, if Child class is not linked to it? :D lol!
 [2005-10-02 13:34 UTC] kowalski-kamil at wp dot pl
I can afford to correct code:

class Base
{
  static function test1() {self::test2();}
  static function test2() {echo 'failure';}
}

class Child extends Base
{
  static function test2() {echo 'success';}
}

Child::test1();

pornel - it's ok?
 [2005-10-03 11:14 UTC] tony2001@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Nov 24 19:01:32 2024 UTC