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

Description

This error signals that the wrong type of data was used when assigning a value to a property. When a type is set on a property, it is always expected to receive that type.

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.