PHP's documentation for "Classes & Objects" seems a little ambiguous to me, so I was wondering if somebody could help me.
<?php
abstract class Base{
static function StaticTest(){
echo get_class();
}
function normalTest(){
echo get_class($this);
}
}
class Test extends Base{
}
$test = new Test;
Test::StaticTest(); // Prints "Base"
echo PHP_EOL;
$test->normalTest(); // Prints "Test"
?>
I want both statements to print "Test". Basically, I want to be able to get the inherited class' name from a static method without having to override that method (because there will be many children to this Base class and I would rather not have to copy and paste that method every time -- I guess I can, but if there's a better way, it would be better practice to implement it).
self::CLASS gives an error (unexpected class constant or something or other) and get_class(self) yields nothing. get_class() by itself yields "Base" (as demonstrated). And CLASS by itself also yields "Base".
Any suggestions?
http://codepad.org/k4o5nxhN