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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: thixit at yahoo dot com
New email:
PHP Version: OS:

 

 [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-2020 The PHP Group
All rights reserved.
Last updated: Mon Aug 10 03:01:25 2020 UTC