Cannot assign %s to class constant %s::%s of type

Description

Since PHP 8.3, constants may have a type specification. In this case, the default value must match the requested type.

In particular, there is not type juggling, so type has to match exactly.

Example

<?php

class X {
    const int A = '3';
}
?>

Literal Examples

  • Cannot assign string to class constant x::A of type int

Solutions

  • Drop the default value.

  • Adapt the default value to the requested type.

  • Drop the type of the constant.