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

Enum %s cannot include properties

Description

Enumeration cannot define a property. They can only define constants and methods.

Enum can use a trait, and import several methods. Traits can also define properties, which are mixed with the host. On the other hand, enum cannot define properties: when a trait is used by an enumeration, it should not have any properties. It is also the case for traits of traits.

Example

<?php

enum D {
   private $p = 1;
}

trait T {
   private int $property; 
}

enum E {
    use T;
}

?>

Alternatives

  • Remove the property from the trait.
  • Split the trait in two traits, and include the new trait that has no property.