Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Class Aliases

It is possible to make an alias of a class and call it with this new name. It either relies on the use expression, preferable at the beginning of the namespace, or the class_alias() function, for dynamic and application-wide aliases.

use expressions are valid only in one file, while class_alias() impacts the whole application, once it is called. class_alias() may also be used with dynamic elements, such as variables.

<?php

    use a as b;
    
    class_alias('a', 'c');
    
    class a {
        function __construct() {
            print __CLASS__;
        }
    }
    
    new a;
    new b;
    new c;

?>

Documentation

See Also