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

Calling A Function Named readonly() Is Deprecated

readonly has been a semi-reserved word since PHP 8.1, when it became the modifier for readonly properties and classes. It could still be used as the name of a function, class, or constant, and PHP even special-cased a global function literally called readonly() so that WordPress, which ships one, kept working. Until PHP 8.6, declaring and calling such a function produced no warning at all. In PHP 8.6, calling a function named readonly() emits a deprecation notice on every call, in preparation for the word becoming fully reserved.

PHP code

<?php

function readonly() {
    return 'not a property modifier';
}

echo readonly(), "\n";

?>

Before

not a property modifier

After

PHP Deprecated:  Calling a function “readonly” is deprecated in /codes/readonlyFunctionCallDeprecated.php on line 3

Deprecated: Calling a function “readonly” is deprecated in /codes/readonlyFunctionCallDeprecated.php on line 3
not a property modifier

PHP version change

This behavior was deprecated in 8.6.

This behavior changed in .

See Also

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat