I saw this example from php.net:
If you need to access constants, properties, methods of classes or objects you can use reflection, it provides much more details about structure of the object.
example:
class MainClass
{
const name = 'Primary';
public $foo = 'Foo Variable';
}
class ExtendedClass extends MainClass
{
const name = 'Extended';
}
/**
* From Class Name
*/
//get reflection of main class
$mainReflection = new ReflectionClass('MainClass');
if($mainReflection->hasConstant('name'))
var_dump($mainReflection->getConstant('name'));//Primary
//get reflection of extended class
$extendedReflection = new ReflectionClass('ExtendedClass');
if($extendedReflection->hasConstant('name'))
var_dump($extendedReflection->getConstant('name'));//Extended
/**
* From Objects
*/
$main = new MainClass();
$extended = new ExtendedClass();
//get reflection of main class
$mainReflection = new ReflectionObject($main);
if($mainReflection->hasConstant('name'))
var_dump($mainReflection->getConstant('name'));//Primary
//get reflection of extended class
$extendedReflection = new ReflectionObject($extended);
if($extendedReflection->hasConstant('name'))
var_dump($extendedReflection->getConstant('name'));//Extended