Comparison #0000
Source Document
<?php
function addTwoInts(int $a, int $b): int
{
return $a + $b;
}
// Expected usage
echo addTwoInts(7, 14), PHP_EOL;
// Type coercion, from floats
echo addTwoInts(7.0, 14.0), PHP_EOL;
// Type coercion, from numeric strings
echo addTwoInts('7', '14'), PHP_EOL;
// Type coercion, from non-numeric strings
echo addTwoInts('seven', 'fourteen'), PHP_EOL;
Analyses
phan-strict
Line | Column | Details |
---|---|---|
12 |
[warning] PhanTypeMismatchArgument Argument 1 ($a) is 7.0 of type 7.0 but \addTwoInts() takes int defined at samples/0000.php:3 |
|
12 |
[warning] PhanTypeMismatchArgument Argument 2 ($b) is 14.0 of type 14.0 but \addTwoInts() takes int defined at samples/0000.php:3 |
|
15 |
[warning] PhanTypeMismatchArgument Argument 1 ($a) is '7' of type '7' but \addTwoInts() takes int defined at samples/0000.php:3 |
|
15 |
[warning] PhanTypeMismatchArgument Argument 2 ($b) is '14' of type '14' but \addTwoInts() takes int defined at samples/0000.php:3 |
|
18 |
[error] PhanTypeMismatchArgumentReal Argument 1 ($a) is 'seven' of type 'seven' but \addTwoInts() takes int defined at samples/0000.php:3 |
|
18 |
[error] PhanTypeMismatchArgumentReal Argument 2 ($b) is 'fourteen' of type 'fourteen' but \addTwoInts() takes int defined at samples/0000.php:3 |
|
Line | Column | Details |
phan-loose
Line | Column | Details |
---|---|---|
18 |
[error] PhanTypeMismatchArgumentReal Argument 1 ($a) is 'seven' of type 'seven' but \addTwoInts() takes int defined at samples/0000.php:3 |
|
18 |
[error] PhanTypeMismatchArgumentReal Argument 2 ($b) is 'fourteen' of type 'fourteen' but \addTwoInts() takes int defined at samples/0000.php:3 |
phpstan-strict
Line | Column | Details |
---|---|---|
12 | 1 |
[error] argument.type Parameter #1 $a of function addTwoInts expects int, float given. |
12 | 1 |
[error] argument.type Parameter #2 $b of function addTwoInts expects int, float given. |
15 | 1 |
[error] argument.type Parameter #1 $a of function addTwoInts expects int, string given. |
15 | 1 |
[error] argument.type Parameter #2 $b of function addTwoInts expects int, string given. |
18 | 1 |
[error] argument.type Parameter #1 $a of function addTwoInts expects int, string given. |
18 | 1 |
[error] argument.type Parameter #2 $b of function addTwoInts expects int, string given. |
Line | Column | Details |
psalm-strict
Line | Column | Details |
---|---|---|
12 | 17 |
[error] n/a InvalidScalarArgument: Argument 1 of addTwoInts expects int, but float(7) provided |
12 | 22 |
[error] n/a InvalidScalarArgument: Argument 2 of addTwoInts expects int, but float(14) provided |
15 | 17 |
[error] n/a InvalidScalarArgument: Argument 1 of addTwoInts expects int, but '7' provided |
15 | 22 |
[error] n/a InvalidScalarArgument: Argument 2 of addTwoInts expects int, but '14' provided |
18 | 17 |
[error] n/a InvalidScalarArgument: Argument 1 of addTwoInts expects int, but 'seven' provided |
18 | 26 |
[error] n/a InvalidScalarArgument: Argument 2 of addTwoInts expects int, but 'fourteen' provided |
Line | Column | Details |