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 redefine class constant %s::%s

Description

PHP does not allow the same constant twice in the same class. The constant may be declared several times in different classes, including extending or extended ones, or in trait, as each case has conflict resolution mechanisms.

Example

<?php

class C {
    const FOO = hello;
    const FOO = hello again;
}

?>

Literal Examples

  • Cannot redefine class constant C::FOO

Alternatives

  • Rename one of the conflicting constants.
  • Remove one of the conflicting constants.

Changed Behavior

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