Cannot assign %s to property %s::$%s of type %s

Description

This error signals that the wrong type was used when assigning values to a property.

Example

<?php

class X {
    public int $property;
}

$x = new X;
$x->property = 'de';

?>

Literal Examples

  • Cannot assign string to property X::$property of type int

Solutions

  • Add the type of this value to the type description.

  • Remove the type on the property.

  • Cast the value to the correct type.