← All results

scalar

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

int|float|string|bool — the four types that are not arrays, objects, null or resources. PHPStan reads the bare word as a class first and only falls back to the union when no such class is in scope, so the spelling is one of the few whose meaning depends on what else the file declares. References: - PHPStan TypeNodeResolver scalar resolves to int|float|string|bool, after trying a pseudo-type class

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 Enforced
phpdoc_advanced_fallback_scalar.php:47: Argument 1 ($value) is [1,2] of type array{0:1,1:2} but \Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar() takes bool|float|int|string (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_scalar.php:32 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]
phpdoc_advanced_fallback_scalar.php:48: Argument 1 ($value) is new \stdClass() of type \stdClass but \Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar() takes bool|float|int|string (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_scalar.php:32 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]
phpdoc_advanced_fallback_scalar.php:49: Argument 1 ($value) is null of type null but \Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar() takes bool|float|int|string (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_scalar.php:32 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]
  • Recognition: spelling resolved
  • Enforcement: 3/3 of the expected violations reported
phpstan 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 Enforced reported Lv.5+
phpdoc_advanced_fallback_scalar.php:47: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar expects bool|float|int|string, array<int, int> given. [identifier=argument.type] [reported-from-level=5]
phpdoc_advanced_fallback_scalar.php:48: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar expects bool|float|int|string, stdClass given. [identifier=argument.type] [reported-from-level=5]
phpdoc_advanced_fallback_scalar.php:49: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar expects bool|float|int|string, null given. [identifier=argument.type] [reported-from-level=5]
With strict-rules
phpdoc_advanced_fallback_scalar.php:47: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar expects bool|float|int|string, array<int, int> given. [identifier=argument.type]
phpdoc_advanced_fallback_scalar.php:48: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar expects bool|float|int|string, stdClass given. [identifier=argument.type]
phpdoc_advanced_fallback_scalar.php:49: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar expects bool|float|int|string, null given. [identifier=argument.type]
  • Recognition: spelling resolved
  • Enforcement: 3/3 of the expected violations reported
psalm 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac
next: 7.0.0-beta19
Enforced
phpdoc_advanced_fallback_scalar.php:47: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar expects scalar, but list{1, 2} provided [InvalidArgument]
phpdoc_advanced_fallback_scalar.php:48: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar expects scalar, but stdClass provided [InvalidArgument]
phpdoc_advanced_fallback_scalar.php:49: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar cannot be null, null value provided to parameter with type scalar [NullArgument]
  • Recognition: spelling resolved
  • Enforcement: 3/3 of the expected violations reported
mago 1.46.0mago 1.46.0 Enforced
phpdoc_advanced_fallback_scalar.php:47: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar`: expected `scalar`, but found `list{int(1), int(2)}`. [invalid-argument]
phpdoc_advanced_fallback_scalar.php:48: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar`: expected `scalar`, but found `stdClass`. [invalid-argument]
phpdoc_advanced_fallback_scalar.php:49: Argument #1 of function `Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar` is `null`, but parameter type `scalar` does not accept it. [null-argument]
  • Recognition: spelling resolved
  • Enforcement: 3/3 of the expected violations reported
mir 0.70.1mir 0.70.1 Enforced
phpdoc_advanced_fallback_scalar.php:47: InvalidArgument: Argument $value of acceptsScalar() expects 'scalar', got 'array{0: 1, 1: 2}' [MIR0201]
phpdoc_advanced_fallback_scalar.php:48: InvalidArgument: Argument $value of acceptsScalar() expects 'scalar', got 'stdClass' [MIR0201]
phpdoc_advanced_fallback_scalar.php:49: NullArgument: Argument $value of acceptsScalar() cannot be null [MIR0100]
  • Recognition: spelling resolved
  • Enforcement: 3/3 of the expected violations reported
phpantom 0.9.0phpantom_lsp 0.9.0 Enforced
phpdoc_advanced_fallback_scalar.php:47: Argument 1 ($value) expects scalar, got list<int> [type_mismatch_argument]
phpdoc_advanced_fallback_scalar.php:48: Argument 1 ($value) expects scalar, got stdClass [type_mismatch_argument]
phpdoc_advanced_fallback_scalar.php:49: Argument 1 ($value) expects scalar, got null [type_mismatch_argument]
  • Recognition: spelling resolved
  • Enforcement: 3/3 of the expected violations reported
intelephense 1.18.5intelephense 1.18.5 Incidental (0/3)
phpdoc_advanced_fallback_scalar.php:26: Expected type 'string|int'. Found 'int|string|array'. [P1006]
  • Recognition: spelling resolved
  • Enforcement: 0/3 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_scalar.php:47: Argument '1' passed to Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar() is expected to be of type bool|float|int|string, array given
phpdoc_advanced_fallback_scalar.php:48: Argument '1' passed to Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar() is expected to be of type bool|float|int|string, stdClass given
phpdoc_advanced_fallback_scalar.php:49: Argument '1' passed to Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar() is expected to be of type bool|float|int|string, null given
  • Recognition: spelling resolved
  • Enforcement: 3/3 of the expected violations reported
qodana 262.8665.325Qodana 262.8665.325 Partly enforced (2/3)
phpdoc_advanced_fallback_scalar.php:47: Parameter '[1, 2]' type is not compatible with declaration [PhpParamsInspection]
phpdoc_advanced_fallback_scalar.php:48: Parameter 'new \stdClass()' type is not compatible with declaration [PhpParamsInspection]
  • Recognition: spelling resolved
  • Enforcement: 2/3 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 Unrecognized ⚠ 1 false positive
phpdoc_advanced_fallback_scalar.php:12: Class or interface named \Conformance\Tests\PhpdocAdvancedFallbackScalar\scalar does not exist [undefinedClass]
phpdoc_advanced_fallback_scalar.php:30: Class or interface named \Conformance\Tests\PhpdocAdvancedFallbackScalar\scalar does not exist [undefinedClass]
phpdoc_advanced_fallback_scalar.php:44: potentially not safe access in parameter value of function Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar [notSafeCall]
phpdoc_advanced_fallback_scalar.php:49: null passed to non-nullable parameter value in function Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar [notNullSafetyFunctionArgumentConstFetch]
  • Recognition: spelling not resolved — reported on declaration line(s) 30
  • Enforcement: 1/3 of the expected violations reported — incidental, since the spelling was not resolved
  • False positives: line(s) 12
Expectation diff
Line 44: Expected valid value to be accepted, got ["potentially not safe access in parameter value of function Conformance\\Tests\\PhpdocAdvancedFallbackScalar\\acceptsScalar [notSafeCall]"]
Line 12: Unexpected errors ["Class or interface named \\Conformance\\Tests\\PhpdocAdvancedFallbackScalar\\scalar does not exist [undefinedClass]"]
steins 0.1.5steins 0.1.5 (2026-08-12 revision 39b4cc1) Enforced
phpdoc_advanced_fallback_scalar.php:47: argument [1, 2] to acceptsScalar() violates declared @param scalar $value — declared contract violation [phpdoc.param-mismatch]
phpdoc_advanced_fallback_scalar.php:48: argument new stdClass() to acceptsScalar() violates declared @param scalar $value — declared contract violation [phpdoc.param-mismatch]
phpdoc_advanced_fallback_scalar.php:49: argument null to acceptsScalar() violates declared @param scalar $value — declared contract violation [phpdoc.param-mismatch]
  • Recognition: spelling resolved
  • Enforcement: 3/3 of the expected violations reported
phpstan-strict 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 Enforced
phpdoc_advanced_fallback_scalar.php:47: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar expects bool|float|int|string, array<int, int> given. [identifier=argument.type]
phpdoc_advanced_fallback_scalar.php:48: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar expects bool|float|int|string, stdClass given. [identifier=argument.type]
phpdoc_advanced_fallback_scalar.php:49: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar expects bool|float|int|string, null given. [identifier=argument.type]
  • Recognition: spelling resolved
  • Enforcement: 3/3 of the expected violations reported
psalm-next 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 Enforced
phpdoc_advanced_fallback_scalar.php:47: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar expects scalar, but list{1, 2} provided [InvalidArgument]
phpdoc_advanced_fallback_scalar.php:48: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar expects scalar, but stdClass provided [InvalidArgument]
phpdoc_advanced_fallback_scalar.php:49: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackScalar\acceptsScalar cannot be null, null value provided to parameter with type scalar [NullArgument]
  • Recognition: spelling resolved
  • Enforcement: 3/3 of the expected violations reported

Source

<?php

declare(strict_types=1);

namespace Conformance\Tests\PhpdocAdvancedFallbackScalar;

/**
 * `scalar`
 *
 * `int|float|string|bool` — the four types that are not arrays, objects, null
 * or resources. PHPStan reads the bare word as a class first and only falls
 * back to the union when no such class is in scope, so the spelling is one of
 * the few whose meaning depends on what else the file declares.
 *
 * References:
 * - PHPStan TypeNodeResolver `scalar` resolves to int|float|string|bool, after trying a pseudo-type class
 */

/**
 * @return scalar
 */
function returnsScalar() // T: scalar
{
    $values = [1, 1.5, 'x', true];

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

/**
 * @param scalar $value
 */
function acceptsScalar($value): void // T: scalar
{
}

// The spelling round-trips: what `@return scalar` produces is what `@param
// scalar` accepts.
acceptsScalar(returnsScalar()); // V

// All four members satisfy the parameter.
acceptsScalar(1); // V
acceptsScalar(1.5); // V
acceptsScalar('x'); // V
acceptsScalar(true); // V

// Everything else is outside the union.
acceptsScalar([1, 2]); // E?: an array is not a scalar
acceptsScalar(new \stdClass()); // E?: an object is not a scalar
acceptsScalar(null); // E?: null is not a scalar