php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41762 Fix of bug #30828 means there is no way to get class name statically.
Submitted: 2007-06-21 12:41 UTC Modified: 2007-06-22 17:58 UTC
From: php at kennel17 dot co dot uk Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.3 OS: N/A
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: php at kennel17 dot co dot uk
New email:
PHP Version: OS:

 

 [2007-06-21 12:41 UTC] php at kennel17 dot co dot uk
Description:
------------
Before bug #30828 was fixed, debug_backtrace() could be used to get the name of a class when the class was extended from a parent class and being called statically.  The new change removes this functionality, and as far as I can see there is no replacement. Perhaps, I am just unaware of an alternative method of achieving this, but if not then this is a vital piece of functionality that has gone missing!


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

  function get_class_static() {
    $bt = debug_backtrace();
    if (isset($bt[1]['object']))
        return get_class($bt[1]['object']);
    else
        return $bt[1]['class'];
  }

  class foo {
    function printClassName() {
      print(get_class_static() . "<br>");
     }
  }

  class bar extends foo {
  }

foo::printClassName();
bar::printClassName();

?>

Expected result:
----------------
In PHP4 the output was:

foo
bar

Actual result:
--------------
In PHP5 the output is:

foo
foo

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-21 22:45 UTC] johannes@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

Maybe we get a proper implementation for late static binding till then there is no reliable way to get the information.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Jul 16 21:00:02 2026 UTC