Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Type declaration ‘%s’ must be unqualified

Description

Scalar types are absolute, and shall not be written with the initial \. It is always omitted.

This error is reported for string, int, bool, iterable, never, void, object, float, null, mixed, true, false.

For some reason, array and callable are still not reported with this error. resource is also ignored, although it is only reserved, and not supported anyway.

Example

<?php

    function foo(\string $x) {}

?>

Literal Examples

  • Type declaration ‘array’ must be unqualified
  • Type declaration ‘string’ must be unqualified
  • Type declaration ‘int’ must be unqualified
  • Type declaration ‘null’ must be unqualified

Alternatives

  • Remove the leading backslash.
  • Remove the whole type.
  • Use a class type, which supports the leading backslash.