Type of %s::$%s must be %s%s (as in class %s)

Description

Property definitions must be compatible one another, between a parent and a child class. With this error message, the parent class defined a type for the property, and so, the child class should also define it. On the other hand, it may change the default value.

Example

<?php

class X {
    public $a;
}

class Y extends X {
    public array $a;
}

?>

Literal Examples

  • Type of X::$a must be array (as in class Y)

Solutions

  • Use the type to the child class in the parent, and the sibling classes.

  • Use the type of the parent class.