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

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

Alternatives

  • 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