I have a base class with a function, and several classes that derive from the base class. Some of these derived classes override the function, some don't.
Is there a way to check if a particular object, which is known to be one of the derived classes, has overridden that function?
Example:
<?php
class BaseThing
{
function Bla() { echo "Hello, this is the base class\n"; }
}
class DerivedThing extends BaseThing
{
function Bla() { echo "Hello, this is a derived class\n"; }
}
class AnotherDerivedThing extends BaseThing
{
// Does not override Bla()
}
$a = new BaseThing();
$b = new DerivedThing();
$c = new AnotherDerivedThing();
$a->Bla(); // prints base class
$b->Bla(); // prints derived class
$c->Bla(); // prints base class
if (method_exists($b,'Bla')) echo "Method 'Bla' exists in DerivedThing\n";
if (method_exists($c,'Bla')) echo "Method 'Bla' exists in AnotherDerivedThing\n";
?>
I tried using method_exists but apparently it says $c contains the method because it's derived from a class that does.
Is there a way to check if an object overrides a particular function? E.g. in the example above, can I somehow detect that $b does override the Bla() function but $c does not?