|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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). PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 17:00:01 2025 UTC |
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?