Using “_” as %s is deprecated since 8.4

Description

_ (underscore) is a valid class name, although it has become a reserved PHP word in PHP 8.4. In the future, it may be used for pattern matching, and by anticipation, it is not allowed for other usage that may ultimately conflict with it.

This applies to classes, traits, interfaces and enumerations. There is already an extension function called _, which is an alias of gettext, from the eponymous extension.

This applies in every name spaces.

Example

<?php

class _ {}

?>

Solutions

  • Use another name.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See ClassUnderscore.

Static Analysis

This error may be tracked down with the following static analysis rules: Php/NoClassUnderscore.