Get the unqualified Class Name of an Object (highly performant)
For now, this seems to be the most performant way to get the class name - without any prefixed namespace - of an object:
public function getClassName() {
$fullClassName = get_class($this);
$lastSeperator = strrpos($fullClassName, '\\');
$shortClassName = substr($fullClassName, $lastSeperator + 1);
return $shortClassName;
}
even shorter:
public function getClassName($obj) {
$fullClassName = get_class($obj);
return substr($fullClassName, strrpos($fullClassName, '\\') + 1);
}
Written by Robin von den Bergen
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#