Explode
public function getName() {
$path = explode('\\', __CLASS__);
return array_pop($path);
}
ReflectionClass
(new \ReflectionClass($this))->getShortName();
Substring
return substr(strrchr(__CLASS__, "\\"), 1);
The winner
Method Name | Iterations | Average Time | Ops/second |
---|---|---|---|
testExplode | 10,000 | 0.0000020221710 | 494,518.01547 |
testSubstring | 10,000 | 0.0000017177343 | 582,162.19968 |
testReflection | 10,000 | 0.0000015984058 | 625,623.34059 |