Check is alias:
<?php
function is_alias(string $class): bool
{
return $class !== (new ReflectionClass($class))->name;
}
?>
Get class aliases:
<?php
function get_class_aliases(string $class, bool $throw = false): ?array
{
static $classes = [];
if (! class_exists($class, true)) {
if ($throw) {
throw new InvalidArgumentException('Class ' . $class . ' not exists');
}
return null;
}
$newClasses = array_diff(get_declared_classes(), array_keys($classes));
if ($newClasses) {
$abc = range('a', 'z');
foreach ($newClasses as $newClass) {
if (in_array($newClass[0], $abc, true)) {
$realClass = (new ReflectionClass($newClass))->getName();
$classes[$newClass] = $newClass !== $realClass ? $realClass : null;
} else {
$classes[$newClass] = null;
}
}
unset($abc, $newClasses);
}
if (! empty($classes[$class])) {
if ($throw) {
throw new InvalidArgumentException($class . ' is alias for class ' . $classes[$class]);
}
return null;
}
return array_keys($classes, $class, true);
}
?>
Usage:
<?php
class Foo {}
class_alias('Foo', 'Bar');
class_alias('Bar', 'Baz');
$aliases = get_class_aliases('Foo', true); ?>