php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35540 get_class() and get_class($this) inconsistent in inherited functions
Submitted: 2005-12-04 03:20 UTC Modified: 2005-12-04 12:27 UTC
From: sam at ombwa dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5CVS-2005-12-04 (snap) OS: Win2K
Private report: No CVE-ID: None
 [2005-12-04 03:20 UTC] sam at ombwa dot com
Description:
------------
In an inherited function,
get_class()      gives the name of the parent class
get_class($this) gives the name of the child class.
These should be consistent and return the name of the child class.

Before you get deja vu and mark this bogus, I think that 31716 and 31616 were closed improperly as they deal with inheitance, NOT static isuses like 30964/30140.

Reproduce code:
---------------
<?php
class Parentclass {
    function inherited_func() {
        echo "In inherited_func():\n__CLASS__ = " .     __CLASS__ . "\nget_class() = " . get_class()      . "\nget_class(\$this) = " . get_class($this) . "\n";
    }
}

class Childclass extends Parentclass {
    function func() {
        echo "In func():\n__CLASS__ = " . __CLASS__ . "\nget_class() = " . get_class()      . "\nget_class(\$this) = " . get_class($this) . "\n";
    }
}
$c = new Childclass();
echo "<pre> phpversion()=" . phpversion() . "\n";
$c->func();
$c->inherited_func();
?>

Expected result:
----------------
I expect get_class() and get_class($this) to return "Childclass".

Actual result:
--------------
 phpversion()=5.1.2-dev
In func():
__CLASS__ = Childclass
get_class() = Childclass
get_class($this) = Childclass
In inherited_func():
__CLASS__ = Parentclass
get_class() = Parentclass
get_class($this) = Childclass

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-04 12:27 UTC] tony2001@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


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 02 12:01:30 2024 UTC