|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-10-13 18:38 UTC] colder@php.net
[2008-10-13 18:39 UTC] colder@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 08:00:01 2025 UTC |
Description: ------------ A getInstance() method is a fairly common design-pattern, yet it's impossible to create such a function in a base-class and have it function as expected when access via the inheriting class. I understand that this is documented behavior, and that it's probably impossible to achieve this using existing syntax/functions. What I'm hoping for is a new function; something like get_statis_class(void) that will return the name of the class used to *access* the static method, not the name of the class in which it was defined. I can provide more elaboration on why this is a nice feature if needed. The attached example is kept short to illustrate the problem as clearly as possible. Reproduce code: --------------- <?php class base { public static function getInstance() { $class = __CLASS__; return new $class(); } } class heir extends base { } $instance = heir::getInstance(); die(get_class($instance)); ?> Expected result: ---------------- heir Actual result: -------------- base