I expected the first example code produces the result same as the second one but it didn't. So in order to get the correct class name, I have to redefine the custom msg()
method in the extended class.
I'd like to know why the first one does not produce the extended class name and why it does when the method is redefined which is exactly the same.
Example 1
call_user_func(array(new MyClass_Mod, "msg"));
class MyClass {
function msg() {
echo '<p>get_class(): ' . get_class() . '</p>';
}
}
class MyClass_Mod extends MyClass {
}
output
get_class(): MyClass
Example 2
call_user_func(array(new MyClass_Mod, "msg"));
class MyClass {
function msg() {
echo '<p>get_class(): ' . get_class() . '</p>';
}
}
class MyClass_Mod extends MyClass {
function msg() {
echo '<p>get_class(): ' . get_class() . '</p>';
}
}
output
get_class(): MyClass_Mod
I'd like to know the mechanism, so please do not suggest to use get_called_class()
. I'm not able to use it for the version below PHP 5.3. Thanks for your input.