Is there a simple way to get the class name without the namespace without using Reflection?
This is my class and when I call get_class()
I get CRMPiccoBundleServicesRFCWebhookSiteCancelled
JavaScript
x
namespace CRMPiccoBundleServicesRFCWebhook;
class SiteCancelled extends Base implements Interface
{
public function process() {
// echo get_class()
}
}
Advertisement
Answer
Or simply exploding the return from class_name
and getting the last element:
JavaScript
$class_parts = explode('\', get_class());
echo end($class_parts);
Or simply removing the namespace from the output of get_class
:
JavaScript
echo str_replace(__NAMESPACE__ . '\', '', get_class());
Either works with or without namespace.
And so on.