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 foo(int $a) {}
foo(1);
foo(1.3);
//Fatal error: Uncaught TypeError: foo(): 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 and PHP RFC: Unify PHP’s typing modes (aka remove strict_types declare).
Related : Type System, declare(), __toString() Method, Type Checking
Added in PHP 7.0