Cannot use ‘never’ as class name as it is reserved

Description

never is a PHP reserved keyword, since PHP 8.1. Until then, it was possible to use it anywhere as names, but since PHP 8.1, it is forbidden with class names, interfaces, enumerations and traits.

The same error is used for all CITE structures : class, interfaces, traits and enumerations.

Namespaces do not solve this issue.

never as a function, method, property, global or class constants is legit.

Example

<?php

class Never {}
interface Never {}
trait Never {}
enum Never {}

?>

Solutions

  • Use another name for that class.