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

Interface Constant Visibility Checks

PHP checks if the visibility of constants that are also part of an interface are all public. If the class constant, in the class, is not public, it is a Fatal Error. This was not checked until PHP 8.3.

PHP code

<?php

interface i {
        public const I = 1;
        public const J = 2;
}

class x implements i {
        private const I = 1;
        public const J = 2;
}

print x::J;
print x::I;
?>

Before

Cannot access private constant x::I

After

Access level to x::I must be public (as in interface i)

PHP version change

This behavior changed in 8.3.

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat