The class_alias Function
The class_alias
function creates an alias for the specified class.
The first parameter accepts the name of the original class, the second - the name of the alias.
The third optional parameter determines whether the function should be called by autoload.
Syntax
class_alias(original, alias, [autoload]);
Example
Let's create a class and its alias:
<?php
class MyClass {
public function test() {
return 'Hello';
}
}
class_alias('MyClass', 'MyAlias');
$obj = new MyAlias();
echo $obj->test();
?>
Code execution result:
'Hello'
Example
Let's check if the class alias exists:
<?php
class TestClass {}
class_alias('TestClass', 'TC');
if (class_exists('TC')) {
echo 'Alias exists';
}
?>
Code execution result:
'Alias exists'
See Also
-
the class_exists function,
which checks a class -
the get_class function,
which returns the object's class -
the interface_exists function,
which checks an interface -
the trait_exists function,
which checks a trait