335 of 410 menu

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

byenru