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

Constants In Trait

Trait can define constants, like a class or an interface. Until PHP 8.3, constants cannot be set in traits, and end with a compilation error.

PHP code

<?php

trait T {
    const X = 1;
}

class X {
	use T;
}

echo X::X;

?>

Before

PHP Fatal error:  Traits cannot have constants

After

1

PHP version change

This behavior changed in 8.3.

Error Messages

Extension

Analyzer

© 2023-2026, Damien Seguy - Exakat