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 redeclare %s::$%s

Description

A property can only be declared once in a class. This error appears when the same property name is declared twice in the same class body, regardless of whether the visibility or default value differ between the two declarations.

The same restriction applies to promoted properties: a constructor parameter promoted to a property cannot share its name with a property already declared in the class body.

Example

<?php

class X {
    public $a;
    public $a;
}

?>

Literal Examples

  • Cannot redeclare X::$a

Alternatives

  • Remove one of the two duplicate property declarations.
  • Rename one of the two properties.

Changed Behavior

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