Default value for parameters with a %s type can only be %s or NULL

Description

The default value of the parameter is not compatible with the type of the same parameter. In the example here, the paramter $s is supposed to be an integer, but has a string as default value.

This error also applies to numeric strings: the default value must be of the same type, without any silent type juggling.

Example

<?php
<?php

function foo(int $s = 's') { }

function bar(int $s = '1') { }

?>

Solutions

  • Change the type of the parameter.

  • Change the default value.

  • Change the default value to NULL.

  • Remove the default value.

  • Remove the type value.

  • Add a second union type to the paramter.