← All results

numeric

Group: Advanced PHPDoc types · Category: ecosystem · File: phpdoc_advanced_fallback_numeric.php

int|float|numeric-stringnumber widened by exactly one member. It is the PHPDoc spelling of what is_numeric() accepts, so '123' and '1.5e3' are in and 'abc' is out. Analyzers that model it reject a non-numeric literal; others fall back to mixed and accept it. References: - PHPStan TypeNodeResolver numeric resolves to int|float|(string&AccessoryNumericStringType)

Analyzer results

AnalyzerVersionResultDiagnostics
phan 6.0.7Phan 6.0.7 php-ast version 1.1.3 PHP version used to run Phan: 8.5.9 Unrecognized
phpdoc_advanced_fallback_numeric.php:22: Return type of returnsNumeric() is undeclared type \Conformance\Tests\PhpdocAdvancedFallbackNumeric\numeric [PhanUndeclaredTypeReturnType]
phpdoc_advanced_fallback_numeric.php:26: Returning $values[\array_rand($values)] of type float (value: 1.5)|int (value: 1)|string (real type ?'123'|?1|?1.5) but returnsNumeric() is declared to return \Conformance\Tests\PhpdocAdvancedFallbackNumeric\numeric (no real type) (the inferred real return type has nothing in common with the declared phpdoc return type) [PhanTypeMismatchReturnProbablyReal]
phpdoc_advanced_fallback_numeric.php:32: Parameter $value has undeclared type \Conformance\Tests\PhpdocAdvancedFallbackNumeric\numeric [PhanUndeclaredTypeParameter]
phpdoc_advanced_fallback_numeric.php:39: Argument 1 ($value) is 1 of type int (value: 1) but \Conformance\Tests\PhpdocAdvancedFallbackNumeric\acceptsNumeric() takes \Conformance\Tests\PhpdocAdvancedFallbackNumeric\numeric (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_numeric.php:32 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]
phpdoc_advanced_fallback_numeric.php:40: Argument 1 ($value) is 1.5 of type float (value: 1.5) but \Conformance\Tests\PhpdocAdvancedFallbackNumeric\acceptsNumeric() takes \Conformance\Tests\PhpdocAdvancedFallbackNumeric\numeric (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_numeric.php:32 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]
phpdoc_advanced_fallback_numeric.php:41: Argument 1 ($value) is '123' of type string but \Conformance\Tests\PhpdocAdvancedFallbackNumeric\acceptsNumeric() takes \Conformance\Tests\PhpdocAdvancedFallbackNumeric\numeric (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_numeric.php:32 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]
phpdoc_advanced_fallback_numeric.php:42: Argument 1 ($value) is '1.5e3' of type string but \Conformance\Tests\PhpdocAdvancedFallbackNumeric\acceptsNumeric() takes \Conformance\Tests\PhpdocAdvancedFallbackNumeric\numeric (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_numeric.php:32 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]
phpdoc_advanced_fallback_numeric.php:45: Argument 1 ($value) is 'abc' of type string but \Conformance\Tests\PhpdocAdvancedFallbackNumeric\acceptsNumeric() takes \Conformance\Tests\PhpdocAdvancedFallbackNumeric\numeric (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_numeric.php:32 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]
phpdoc_advanced_fallback_numeric.php:48: Argument 1 ($value) is true of type true but \Conformance\Tests\PhpdocAdvancedFallbackNumeric\acceptsNumeric() takes \Conformance\Tests\PhpdocAdvancedFallbackNumeric\numeric (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_numeric.php:32 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]
  • Recognition: spelling not resolved — reported on declaration line(s) 22, 32
  • Enforcement: 2/2 of the expected violations reported — incidental, since the spelling was not resolved
Expectation diff
Line 26: Expected valid value to be accepted, got ["Returning $values[\\array_rand($values)] of type float (value: 1.5)|int (value: 1)|string (real type ?'123'|?1|?1.5) but returnsNumeric() is declared to return \\Conformance\\Tests\\PhpdocAdvancedFallbackNumeric\\numeric (no real type) (the inferred real return type has nothing in common with the declared phpdoc return type) [PhanTypeMismatchReturnProbablyReal]"]
Line 39: Expected valid value to be accepted, got ["Argument 1 ($value) is 1 of type int (value: 1) but \\Conformance\\Tests\\PhpdocAdvancedFallbackNumeric\\acceptsNumeric() takes \\Conformance\\Tests\\PhpdocAdvancedFallbackNumeric\\numeric (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_numeric.php:32 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]"]
Line 40: Expected valid value to be accepted, got ["Argument 1 ($value) is 1.5 of type float (value: 1.5) but \\Conformance\\Tests\\PhpdocAdvancedFallbackNumeric\\acceptsNumeric() takes \\Conformance\\Tests\\PhpdocAdvancedFallbackNumeric\\numeric (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_numeric.php:32 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]"]
Line 41: Expected valid value to be accepted, got ["Argument 1 ($value) is '123' of type string but \\Conformance\\Tests\\PhpdocAdvancedFallbackNumeric\\acceptsNumeric() takes \\Conformance\\Tests\\PhpdocAdvancedFallbackNumeric\\numeric (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_numeric.php:32 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]"]
Line 42: Expected valid value to be accepted, got ["Argument 1 ($value) is '1.5e3' of type string but \\Conformance\\Tests\\PhpdocAdvancedFallbackNumeric\\acceptsNumeric() takes \\Conformance\\Tests\\PhpdocAdvancedFallbackNumeric\\numeric (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_numeric.php:32 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]"]
phpstan 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 Enforced reported Lv.5+
phpdoc_advanced_fallback_numeric.php:45: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackNumeric\acceptsNumeric expects float|int|numeric-string, 'abc' given. [identifier=argument.type] [reported-from-level=5]
phpdoc_advanced_fallback_numeric.php:48: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackNumeric\acceptsNumeric expects float|int|numeric-string, true given. [identifier=argument.type] [reported-from-level=5]
With strict-rules
phpdoc_advanced_fallback_numeric.php:45: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackNumeric\acceptsNumeric expects float|int|numeric-string, 'abc' given. [identifier=argument.type]
phpdoc_advanced_fallback_numeric.php:48: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackNumeric\acceptsNumeric expects float|int|numeric-string, true given. [identifier=argument.type]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
psalm 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac
next: 7.0.0-beta19
Enforced
phpdoc_advanced_fallback_numeric.php:45: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackNumeric\acceptsNumeric expects numeric, but 'abc' provided [InvalidArgument]
phpdoc_advanced_fallback_numeric.php:48: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackNumeric\acceptsNumeric expects numeric, but true provided [InvalidArgument]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
mago 1.46.0mago 1.46.0 Enforced
phpdoc_advanced_fallback_numeric.php:45: Possible argument type mismatch for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackNumeric\acceptsNumeric`: expected `numeric`, but possibly received `string('abc')`. [possibly-invalid-argument]
phpdoc_advanced_fallback_numeric.php:48: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackNumeric\acceptsNumeric`: expected `numeric`, but found `true`. [invalid-argument]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
mir 0.70.1mir 0.70.1 Incidental (2/2)
phpdoc_advanced_fallback_numeric.php:26: InvalidReturnType: Return type '1|1.5|"123"' is not compatible with declared 'numeric' [MIR0200]
phpdoc_advanced_fallback_numeric.php:41: InvalidArgument: Argument $value of acceptsNumeric() expects 'numeric', got '"123"' [MIR0201]
phpdoc_advanced_fallback_numeric.php:42: InvalidArgument: Argument $value of acceptsNumeric() expects 'numeric', got '"1.5e3"' [MIR0201]
phpdoc_advanced_fallback_numeric.php:45: InvalidArgument: Argument $value of acceptsNumeric() expects 'numeric', got '"abc"' [MIR0201]
phpdoc_advanced_fallback_numeric.php:48: InvalidArgument: Argument $value of acceptsNumeric() expects 'numeric', got 'true' [MIR0201]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported — incidental, since values the type admits were also rejected on line(s) 41, 42
Expectation diff
Line 26: Expected valid value to be accepted, got ["InvalidReturnType: Return type '1|1.5|\"123\"' is not compatible with declared 'numeric' [MIR0200]"]
Line 41: Expected valid value to be accepted, got ["InvalidArgument: Argument $value of acceptsNumeric() expects 'numeric', got '\"123\"' [MIR0201]"]
Line 42: Expected valid value to be accepted, got ["InvalidArgument: Argument $value of acceptsNumeric() expects 'numeric', got '\"1.5e3\"' [MIR0201]"]
phpantom 0.9.0phpantom_lsp 0.9.0 Incidental (2/2)
phpdoc_advanced_fallback_numeric.php:41: Argument 1 ($value) expects numeric, got '123' [type_mismatch_argument]
phpdoc_advanced_fallback_numeric.php:42: Argument 1 ($value) expects numeric, got '1.5e3' [type_mismatch_argument]
phpdoc_advanced_fallback_numeric.php:45: Argument 1 ($value) expects numeric, got 'abc' [type_mismatch_argument]
phpdoc_advanced_fallback_numeric.php:48: Argument 1 ($value) expects numeric, got bool [type_mismatch_argument]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported — incidental, since values the type admits were also rejected on line(s) 41, 42
Expectation diff
Line 41: Expected valid value to be accepted, got ["Argument 1 ($value) expects numeric, got '123' [type_mismatch_argument]"]
Line 42: Expected valid value to be accepted, got ["Argument 1 ($value) expects numeric, got '1.5e3' [type_mismatch_argument]"]
intelephense 1.18.5intelephense 1.18.5 Incidental (0/2)
phpdoc_advanced_fallback_numeric.php:26: Expected type 'string|int'. Found 'int|string|array'. [P1006]
  • Recognition: spelling resolved
  • Enforcement: 0/2 of the expected violations reported — incidental, since values the type admits were also rejected on line(s) 26
Expectation diff
Line 26: Expected valid value to be accepted, got ["Expected type 'string|int'. Found 'int|string|array'. [P1006]"]
phpy 0.2.0phpy 0.2.0 Enforced
phpdoc_advanced_fallback_numeric.php:41: Argument '1' passed to Conformance\Tests\PhpdocAdvancedFallbackNumeric\acceptsNumeric() is expected to be of type float|int, string given
phpdoc_advanced_fallback_numeric.php:42: Argument '1' passed to Conformance\Tests\PhpdocAdvancedFallbackNumeric\acceptsNumeric() is expected to be of type float|int, string given
phpdoc_advanced_fallback_numeric.php:45: Argument '1' passed to Conformance\Tests\PhpdocAdvancedFallbackNumeric\acceptsNumeric() is expected to be of type float|int, string given
phpdoc_advanced_fallback_numeric.php:48: Argument '1' passed to Conformance\Tests\PhpdocAdvancedFallbackNumeric\acceptsNumeric() is expected to be of type float|int, bool given
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
Expectation diff
Line 41: Expected valid value to be accepted, got ["Argument '1' passed to Conformance\\Tests\\PhpdocAdvancedFallbackNumeric\\acceptsNumeric() is expected to be of type float|int, string given"]
Line 42: Expected valid value to be accepted, got ["Argument '1' passed to Conformance\\Tests\\PhpdocAdvancedFallbackNumeric\\acceptsNumeric() is expected to be of type float|int, string given"]
qodana 262.8665.325Qodana 262.8665.325 Partly enforced (1/2)
phpdoc_advanced_fallback_numeric.php:48: Parameter 'true' type is not compatible with declaration when using strict type matching [PhpParamsInspection]
  • Recognition: spelling resolved
  • Enforcement: 1/2 of the expected violations reported
noverify 0.5.5NoVerify, version 0.5.5: built on: 2025.04.22 14:36:46 OS: r-kuchinskas arm64 Commit: 4774b82f8adc53fbef38f95e97af4b953b4d1529 Partly enforced (1/2)
phpdoc_advanced_fallback_numeric.php:48: potentially not safe access in parameter value of function Conformance\Tests\PhpdocAdvancedFallbackNumeric\acceptsNumeric [notSafeCall]
  • Recognition: spelling resolved
  • Enforcement: 1/2 of the expected violations reported
steins 0.1.5steins 0.1.5 (2026-08-12 revision 39b4cc1) Enforced
phpdoc_advanced_fallback_numeric.php:45: argument "abc" to acceptsNumeric() violates declared @param numeric $value — declared contract violation [phpdoc.param-mismatch]
phpdoc_advanced_fallback_numeric.php:48: argument true to acceptsNumeric() violates declared @param numeric $value — declared contract violation [phpdoc.param-mismatch]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
phpstan-strict 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 Enforced
phpdoc_advanced_fallback_numeric.php:45: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackNumeric\acceptsNumeric expects float|int|numeric-string, 'abc' given. [identifier=argument.type]
phpdoc_advanced_fallback_numeric.php:48: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackNumeric\acceptsNumeric expects float|int|numeric-string, true given. [identifier=argument.type]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
psalm-next 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 Enforced
phpdoc_advanced_fallback_numeric.php:45: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackNumeric\acceptsNumeric expects numeric, but 'abc' provided [InvalidArgument]
phpdoc_advanced_fallback_numeric.php:48: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackNumeric\acceptsNumeric expects numeric, but true provided [InvalidArgument]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported

Source

<?php

declare(strict_types=1);

namespace Conformance\Tests\PhpdocAdvancedFallbackNumeric;

/**
 * `numeric`
 *
 * `int|float|numeric-string` — `number` widened by exactly one member. It is
 * the PHPDoc spelling of what `is_numeric()` accepts, so `'123'` and `'1.5e3'`
 * are in and `'abc'` is out. Analyzers that model it reject a non-numeric
 * literal; others fall back to `mixed` and accept it.
 *
 * References:
 * - PHPStan TypeNodeResolver `numeric` resolves to int|float|(string&AccessoryNumericStringType)
 */

/**
 * @return numeric
 */
function returnsNumeric() // T: numeric
{
    $values = [1, 1.5, '123'];

    return $values[\array_rand($values)]; // V
}

/**
 * @param numeric $value
 */
function acceptsNumeric($value): void // T: numeric
{
}

acceptsNumeric(returnsNumeric()); // V

// Numbers and numeric strings alike satisfy the parameter.
acceptsNumeric(1); // V
acceptsNumeric(1.5); // V
acceptsNumeric('123'); // V
acceptsNumeric('1.5e3'); // V

// A string that is not numeric does not.
acceptsNumeric('abc'); // E?: 'abc' is not numeric

// Nor does a bool.
acceptsNumeric(true); // E?: true is not numeric