php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47316 static get_class() problem with parent/child
Submitted: 2009-02-05 15:11 UTC Modified: 2009-02-06 10:35 UTC
From: john dot oconnor at totemic dot co dot uk Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.8 OS: Linux
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: john dot oconnor at totemic dot co dot uk
New email:
PHP Version: OS:

 

 [2009-02-05 15:11 UTC] john dot oconnor at totemic dot co dot uk
Description:
------------
When calling a function in a static context, it appears that get_class reports its class incorrectly.

Reproduce code:
---------------
class Foo extends Bar
{
  
}

class Bar
{
  function test()
  {
    return get_class(new self);
  }
}

print "Should report 'Foo': " . Foo::test();
print "Should report 'Bar': " . Bar::test();

Expected result:
----------------
Should report 'Foo': Foo
Should report 'Bar': Bar

Actual result:
--------------
Should report 'Foo': Bar
Should report 'Bar': Bar

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-02-05 21:09 UTC] jani@php.net
It's still defined in Bar. No bug here.
 [2009-02-06 10:35 UTC] john dot oconnor at totemic dot co dot uk
I don't understand how its not a bug? A 'workaround' would be using "Late static binding", but that still doesn't solve this bug (And its only available in the alpha release of 5.3.0, not the stable 5.2.8)

Calling a function in Bar from the child Foo:

self should return Foo.
parent should retun Bar.

Whereas if I'm calling Bar directly:

self returns Bar
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 07 15:01:36 2025 UTC