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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
27 - 17 = ?
Subscribe to this entry?

 
 [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: Wed Sep 23 04:01:25 2020 UTC