Cannot declare const %s because

Description

This error is the constant counterpart of the use collision error raised for classes and functions: it fires when a top-level const declaration reuses a name that was already brought into the current file through a use const ... as ... import.

The full message reads: Cannot declare const %s because the name is already in use.

Example

<?php

use const App\FOO as BAR;

const BAR = 42;

?>

Literal Examples

  • Cannot declare const BAR because the name is already in use

Solutions

  • Rename the const declaration.

  • Change the alias used in the use const import.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See ` <https://php-changed-behaviors.readthedocs.io/en/latest/behavior/.html>`_.