php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22960 Value of the constant __CLASS__
Submitted: 2003-03-30 05:54 UTC Modified: 2003-03-31 01:21 UTC
From: thixit at yahoo dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 4.3.1 OS:
Private report: No CVE-ID: None
 [2003-03-30 05:54 UTC] thixit at yahoo dot com
Concerning the magical constant __CLASS__

<?php
class foo
{
    function a()
    {
        print __CLASS__ . "\n";
    }
}

class bar extends foo
{
    function b()
    {
        print __CLASS__ . "\n";
    }
}

$foo = new foo;
$bar = new bar;
print '<pre>';
$foo->a();              // foo
$bar->a();              // foo
$bar->b();              // bar
print '</pre>';
?>

I'm not sure about the definition of magical constant,
but IMHO __CLASS__ should be changed to reflect
the current class that it is in at that moment.
This would be useful when use it in a static method
where get_class() cannot be used.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-03-31 01:21 UTC] sniper@php.net
It works as expected and intended.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 00:01:28 2024 UTC