php define strict types

Solutions on MaxInterview for php define strict types by the best coders in the world

showing results for - "php define strict types"
Maria
08 Nov 2020
1"Strict types" mode only checks types at specific points in the code; it does not track everything that happens to the variable.
2
3Specifically, it checks:
4
5the parameters given to the function, if type hints are included in the signature; here you are giving two ints to a function expecting two ints, so there is no error
6the return value of the function, if a return type hint is included in the signature; here you have no type hint, but if you had a hint of : int, there would still be no error, because the result of $a + $b + $c is indeed an int.
7Here are some examples that do give errors:
8
9declare(strict_types=1);
10$a = '1';
11$b = '2';
12function FunctionName(int $a, int $b)
13{
14    return $a + $b;
15}
16echo FunctionName($a, $b);
Juan David
27 Apr 2016
1declare(strict_types = 1);