php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #43608 get_class() gets __CLASS__ in static methods
Submitted: 2007-12-16 18:26 UTC Modified: 2007-12-16 18:44 UTC
From: mrbizkit at email dot it Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.5 OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mrbizkit at email dot it
New email:
PHP Version: OS:

 

 [2007-12-16 18:26 UTC] mrbizkit at email dot it
Description:
------------
hi, i'm asking for a feature change about this function in static methods and extended classes (please read the reproduce code)

the problem is:
i want to get the caller classname, not the classname where get_class() is used

if you want to fix it [?]
for retrocompatibility issues you can use get_class(NULL[,true]); or a new function

Reproduce code:
---------------
class theparent
{
     public static function test()
     {
          echo get_class() . "\n";
        //echo get_class(NULL,TRUE) . "\n"; [?]
     }
}
class pecl extends theparent{}
class pear extends theparent{}

pecl::test();
pear::test();

Expected result:
----------------
pecl
pear

Actual result:
--------------
theparent
theparent

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-16 18:44 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

That's an feature implemented with PHP 5.3 called "Late Static Binding", see: http://php.net/language.oop5.late-static-bindings
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 22:01:27 2024 UTC