Joined July 2018
·

doublerainbow

Posted to PHP get class name without namespace over 1 year ago

@filpgame
why not
class_basename($objectOrString); ?

class_basename is over 10x slower on my machine anyway

using this script

$time = microtime(true);
for($i=0; $i < 1000000; ++$i){
//$a=explode('\', CLASS); arraypop($a);
// 0.29 sec
substr(strrchr(
CLASS, "\"), 1);
// 0.15 sec
//(new \ReflectionClass($this))->getShortName();
// 0.35 sec
//class
basename(CLASS);
// 3.6 sec
}
var_dump([
$time,
microtime(true),
(microtime(true)-$time),
]);

Achievements
1 Karma
0 Total ProTip Views