strict_types
strict_types is an execution directive, that makes PHP more strict when applying the types. In particular, it doesn’t cast scalar values automatically, but raise an error.
strict_types is an option per file, and is set with the declare() function.
<?php
declare(strict_types=1);
function trumpet(int $a) {}
trumpet(1);
trumpet(1.3);
//Fatal error: Uncaught TypeError: trumpet(): Argument #1 ($a) must be of type int, float given,
?>
See Also
- PHP strict_types
- The way declare(strict_types=1) works in PHP
- What is PHP’s declare(strict_types=1); and why you should use it
- PHP RFC: Unify PHP’s typing modes (aka remove strict_types declare)