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

Final Method In Trait

Trait methods can be named final, when importing them as a trait alias. It was explicitly forbidden until PHP 8.3. This has nothing to do with the final keyword.

PHP code

<?php

trait t {
    function foo() {}
}

trait t2 {
    function foo() {}
}

class A {
        use t, t2 { t::foo as final; }
}
?>

Before


After


PHP version change

This behavior changed in 8.3.

Error Messages

Extension

Analyzer

© 2023-2026, Damien Seguy - Exakat