php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #35266 __CLASS__ is not always right
Submitted: 2005-11-17 17:52 UTC Modified: 2005-11-17 17:55 UTC
From: markus at cultcom dot de Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 5.0.5 OS: Linux (Fedora Core 4)
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: markus at cultcom dot de
New email:
PHP Version: OS:

 

 [2005-11-17 17:52 UTC] markus at cultcom dot de
Description:
------------
__CLASS__ does not contain the correct class name in a generic class if method is called from a derived class.

Reproduce code:
---------------
<?php

class Generic
{
    public static function i_am()
    {
        print __CLASS__ . "\n";
    }
}

class Derived extends Generic
{
}

Generic::i_am();   // correct, print "Generic"
Derived::i_am();   // wrong, should print "Derived"

?>

Expected result:
----------------
If I call a method which was implemented in a parent class I need in any way access to the name of the class which actually was asked to execute the method...


Actual result:
--------------
Always the name of the class that actualy implements the method.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-17 17:55 UTC] tony2001@php.net
__CLASS__ is replaced with it's value during compile time.
Also, I would consider it's right, because this method actually belong to the parent class, not to the derived one.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 15:01:36 2025 UTC