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

Alias multiples

<?php

trait t {
    function foo() {
        echo __METHOD__.PHP_EOL;
    }
}

class x {
    use t {
        foo as goo;
        foo as ioo;
    }
}

(new x)->foo(); // t::foo
(new x)->goo(); // t::foo
(new x)->ioo(); // t::foo

Il est possible de renommer une méthode importée depuis un trait, en utilisant un nom d’alias. Il est également possible de l’importer plusieurs fois, avec des noms différents.

Et, contrairement à static/self, il n’est pas possible pour la méthode appelée de savoir comment elle a été appelée.

See Also

PHP Features

Last updated: 11 October 2026