Typing and strict_types

Type declarations specify the types of a function's parameters and return value (int, string, ?string, array...). With declare(strict_types=1); at the top of the file, PHP refuses implicit conversions and throws a TypeError, which avoids subtle bugs.

Example

declare(strict_types=1);
function double(int $n): int { return $n * 2; }

Related concepts

The whole glossary