class_alias()

The class_alias() function creates an alias for a class, interface, enum or trait. Then, the alias may be used in place of the original name anywhere in the application, including in use expressions.

In PHP 8.3, class_alias() supports the creation of aliases with native PHP classes.

class_alias() is also usable on interfaces, enumerations and traits.

Once created, the objects are of the original class. The alias name doesn’t stick to the objects, and it is not possible to know if the object was created as an alias or the original class. The alias may be used with types.

<?php

class_alias(stdClass::class, StandardClass::class);

$object = new StandardClass();

// stdClass
print gettype($object);

?>

Documentation

See also PHP: Using class_alias to maintain BC while moving/renaming classes

Related : Use