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
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: 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-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 15:01:33 2025 UTC