I have a function with a parameter that is fed a constant.
The constant can come from several classes, see example:
function myFunction($const): string {
// do some stuff
// use the classname do some other stuff
// do some more stuff
return $output;
}
echo myFunction(SomeClass::A_CONSTANT);
echo myFunction(OtherClass::ALSO_A_CONSTANT);
To make things more difficult, the constants I’m getting come from aliased classes, in the class file outside the class you have something like this:
class_alias(RealClass::class, 'SomeClass');
Is there a way to get the classname from the constant?
So from the example above I would get RealClass
when I use the constant SomeClass::A_CONSTANT
.
I can work around the alias, getting SomeClass
when I use SomeClass::A_CONSTANT
is just fine.
I’ve tried get_defined_constants()
, get_class()
, get_parent_class()
& get_called_class()
, but those just get the result or result in errors due to not being in scope or the variable being a string instead of an object.