ID:               47335
 Updated by:       col...@php.net
 Reported By:      php at kennel17 dot co dot uk
 Status:           Bogus
 Bug Type:         Unknown/Other Function
 Operating System: Win32
 PHP Version:      5.3.0beta1
 New Comment:

The problem is that in your last example, the call is not static since
you're in an object context and the getClassName method is not defined
as static. Turn E_STRICT reporting on and you'll get errors about that.


Previous Comments:
------------------------------------------------------------------------

[2009-02-07 18:22:41] php at kennel17 dot co dot uk

I checked the documentation[1] before posting, and according to what it
says there, this is not bogus.  

The documentation simply states that get_called_class() "Gets the name
of the class the static method is called in." In this example, the
static method is in MyClass, so the function should return "MyClass".

Now, either this is a bug in get_called_class(), or it is a bug in the
documentation.  Personally, this function has a lot less utility if you
can't guarantee that it behaves as described below.  How else can you
get the current class name?  If this is intended behaviour, then can you
please point to something that documents the reason for this unintuitive
response.


[1] http://www.php.net/manual/en/function.get-called-class.php

------------------------------------------------------------------------

[2009-02-07 16:21:15] fel...@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



------------------------------------------------------------------------

[2009-02-07 14:54:35] php at kennel17 dot co dot uk

Description:
------------
The new get_called_class() function returns the wrong class name when
called from within a static method, when that function is called from an
instantiated class method.

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

class MyClass {
        function GetClassName() {
                return get_called_class();
        }
}

class OtherClass {
        function Foo() {
                return MyClass::GetClassName();
        }
}

$c = new OtherClass;

print( MyClass::GetClassName() . "\n");
print( OtherClass::Foo() . "\n");
print( $c->Foo() . "\n");

?>

Expected result:
----------------
MyClass
MyClass
MyClass


Actual result:
--------------
MyClass
MyClass
OtherClass



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=47335&edit=1

Reply via email to