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

Relaxed Naming With Class Constant

Relaxed naming is the possibility to use PHP keywords as method or class constant names (for properties, the $ has allowed it for a long time).

private, protected and public were not valid class constant names, until PHP 8.3. They were eligible to be method names, though.

PHP code

<?php

class x {
    public const string private = 'protected';
}

echo x::private;

?>

Before

PHP Parse error:  syntax error, unexpected token "private", expecting "=" 

Parse error: syntax error, unexpected token "private", expecting "=" 

After

protected

PHP version change

This behavior changed in 8.3.

Error Messages

© 2023-2026, Damien Seguy - Exakat