← All results

!== false narrowing with non-falsy-string|false

Group: Assertions and narrowing · Category: ecosystem · File: assertions_non_falsy_string_false_guard.php

References: - Psalm scalar string refinements - PHPStan string refinement docs // E?: some tools misparse reference text mentioning non-falsy-string - common analyzer narrowing on false checks

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 Partly enforced (2/3)
assertions_non_falsy_string_false_guard.php:41: Argument 1 ($value) is $value of type false but \Conformance\Tests\AssertionsNonFalsyStringFalseGuard\takesNonFalsyString() takes non-falsy-string (real type string) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/assertions_non_falsy_string_false_guard.php:19 [PhanTypeMismatchArgumentReal]
assertions_non_falsy_string_false_guard.php:42: Argument 1 ($value) is $value of type false but \Conformance\Tests\AssertionsNonFalsyStringFalseGuard\takesNonEmptyString() takes non-empty-string (real type string) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/assertions_non_falsy_string_false_guard.php:26 [PhanTypeMismatchArgumentReal]
  • Recognition: spelling resolved
  • Enforcement: 2/3 of the expected violations reported
phpstan 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 Partly enforced (2/3) reported Lv.5+
assertions_non_falsy_string_false_guard.php:41: Parameter #1 $value of function Conformance\Tests\AssertionsNonFalsyStringFalseGuard\takesNonFalsyString expects non-falsy-string, false given. [identifier=argument.type] [reported-from-level=5]
assertions_non_falsy_string_false_guard.php:42: Parameter #1 $value of function Conformance\Tests\AssertionsNonFalsyStringFalseGuard\takesNonEmptyString expects non-empty-string, false given. [identifier=argument.type] [reported-from-level=5]
With strict-rules
assertions_non_falsy_string_false_guard.php:41: Parameter #1 $value of function Conformance\Tests\AssertionsNonFalsyStringFalseGuard\takesNonFalsyString expects non-falsy-string, false given. [identifier=argument.type]
assertions_non_falsy_string_false_guard.php:42: Parameter #1 $value of function Conformance\Tests\AssertionsNonFalsyStringFalseGuard\takesNonEmptyString expects non-empty-string, false given. [identifier=argument.type]
  • Recognition: spelling resolved
  • Enforcement: 2/3 of the expected violations reported
psalm 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac
next: 7.0.0-beta19
Partly enforced (2/3)
assertions_non_falsy_string_false_guard.php:41: Argument 1 of Conformance\Tests\AssertionsNonFalsyStringFalseGuard\takesNonFalsyString cannot be false, non-falsy-string value expected [InvalidArgument]
assertions_non_falsy_string_false_guard.php:42: Argument 1 of Conformance\Tests\AssertionsNonFalsyStringFalseGuard\takesNonEmptyString cannot be false, non-empty-string value expected [InvalidArgument]
  • Recognition: spelling resolved
  • Enforcement: 2/3 of the expected violations reported
mago 1.46.0mago 1.46.0 Partly enforced (2/3)
assertions_non_falsy_string_false_guard.php:41: Argument #1 of function `Conformance\Tests\AssertionsNonFalsyStringFalseGuard\takesNonFalsyString` is `false`, but parameter type `truthy-string` does not accept it. [false-argument]
assertions_non_falsy_string_false_guard.php:42: Argument #1 of function `Conformance\Tests\AssertionsNonFalsyStringFalseGuard\takesNonEmptyString` is `false`, but parameter type `non-empty-string` does not accept it. [false-argument]
  • Recognition: spelling resolved
  • Enforcement: 2/3 of the expected violations reported
mir 0.70.1mir 0.70.1 Partly enforced (2/3)
assertions_non_falsy_string_false_guard.php:41: InvalidArgument: Argument $value of takesNonFalsyString() expects 'non-empty-string', got 'false' [MIR0201]
assertions_non_falsy_string_false_guard.php:42: InvalidArgument: Argument $value of takesNonEmptyString() expects 'non-empty-string', got 'false' [MIR0201]
  • Recognition: spelling resolved
  • Enforcement: 2/3 of the expected violations reported
phpantom 0.9.0phpantom_lsp 0.9.0 Incidental (1/3)
assertions_non_falsy_string_false_guard.php:37: Argument 1 ($value) expects non-empty-string, got non-falsy-string|false [type_mismatch_argument]
assertions_non_falsy_string_false_guard.php:42: Argument 1 ($value) expects non-empty-string, got non-falsy-string|false [type_mismatch_argument]
  • Recognition: spelling resolved
  • Enforcement: 1/3 of the expected violations reported — incidental, since values the type admits were also rejected on line(s) 37
Expectation diff
Line 37: Expected valid value to be accepted, got ["Argument 1 ($value) expects non-empty-string, got non-falsy-string|false [type_mismatch_argument]"]
intelephense 1.18.5intelephense 1.18.5 Partly enforced (2/3)
assertions_non_falsy_string_false_guard.php:41: Expected type 'string'. Found 'false'. [P1006]
assertions_non_falsy_string_false_guard.php:42: Expected type 'string'. Found 'false'. [P1006]
  • Recognition: spelling resolved
  • Enforcement: 2/3 of the expected violations reported
phpy 0.2.0phpy 0.2.0 Partly enforced (2/3)
assertions_non_falsy_string_false_guard.php:41: Argument '1' passed to Conformance\Tests\AssertionsNonFalsyStringFalseGuard\takesNonFalsyString() is expected to be of type string, bool given
assertions_non_falsy_string_false_guard.php:42: Argument '1' passed to Conformance\Tests\AssertionsNonFalsyStringFalseGuard\takesNonEmptyString() is expected to be of type string, bool given
  • Recognition: spelling resolved
  • Enforcement: 2/3 of the expected violations reported
qodana 262.8665.325Qodana 262.8665.325 Partly enforced (2/3)
assertions_non_falsy_string_false_guard.php:41: Variable is always 'false' when reached [PhpConditionAlreadyCheckedInspection]
assertions_non_falsy_string_false_guard.php:41: Parameter '$value' type is not compatible with declaration when using strict type matching [PhpParamsInspection]
assertions_non_falsy_string_false_guard.php:41: Parameter '$value' type is not compatible with declaration [PhpStrictTypeCheckingInspection]
assertions_non_falsy_string_false_guard.php:42: Variable is always 'false' when reached [PhpConditionAlreadyCheckedInspection]
assertions_non_falsy_string_false_guard.php:42: Parameter '$value' type is not compatible with declaration when using strict type matching [PhpParamsInspection]
assertions_non_falsy_string_false_guard.php:42: Parameter '$value' type is not compatible with declaration [PhpStrictTypeCheckingInspection]
  • 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
assertions_non_falsy_string_false_guard.php:12: Class or interface named \Conformance\Tests\AssertionsNonFalsyStringFalseGuard\non-falsy-string does not exist [undefinedClass]
assertions_non_falsy_string_false_guard.php:19: param $value miss matched with phpdoc type <<non-falsy-string>> [funcParamTypeMissMatch]
assertions_non_falsy_string_false_guard.php:26: param $value miss matched with phpdoc type <<non-empty-string>> [funcParamTypeMissMatch]
assertions_non_falsy_string_false_guard.php:31: Class or interface named \Conformance\Tests\AssertionsNonFalsyStringFalseGuard\non-falsy-string does not exist [undefinedClass]
assertions_non_falsy_string_false_guard.php:37: potentially not safe call in function Conformance\Tests\AssertionsNonFalsyStringFalseGuard\takesNonEmptyString signature of param value [notSafeCall]
assertions_non_falsy_string_false_guard.php:42: potentially not safe call in function Conformance\Tests\AssertionsNonFalsyStringFalseGuard\takesNonEmptyString signature of param value [notSafeCall]
  • Recognition: spelling not resolved — reported on declaration line(s) 19, 26, 31
  • Enforcement: 2/3 of the expected violations reported — incidental, since the spelling was not resolved
Expectation diff
Line 37: Expected valid value to be accepted, got ["potentially not safe call in function Conformance\\Tests\\AssertionsNonFalsyStringFalseGuard\\takesNonEmptyString signature of param value [notSafeCall]"]
steins 0.1.5steins 0.1.5 (2026-08-12 revision 39b4cc1) Partly enforced (2/3)
assertions_non_falsy_string_false_guard.php:41: argument false (from $value, proven on this branch) to takesNonFalsyString() cannot become string $value — proven TypeError (strict mode) [type.argument-mismatch]
assertions_non_falsy_string_false_guard.php:42: argument false (from $value, proven on this branch) to takesNonEmptyString() cannot become string $value — proven TypeError (strict mode) [type.argument-mismatch]
  • Recognition: spelling resolved
  • Enforcement: 2/3 of the expected violations reported
phpstan-strict 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 Partly enforced (2/3)
assertions_non_falsy_string_false_guard.php:41: Parameter #1 $value of function Conformance\Tests\AssertionsNonFalsyStringFalseGuard\takesNonFalsyString expects non-falsy-string, false given. [identifier=argument.type]
assertions_non_falsy_string_false_guard.php:42: Parameter #1 $value of function Conformance\Tests\AssertionsNonFalsyStringFalseGuard\takesNonEmptyString expects non-empty-string, false given. [identifier=argument.type]
  • Recognition: spelling resolved
  • Enforcement: 2/3 of the expected violations reported
psalm-next 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 Partly enforced (2/3)
assertions_non_falsy_string_false_guard.php:41: Argument 1 of Conformance\Tests\AssertionsNonFalsyStringFalseGuard\takesNonFalsyString cannot be false, non-falsy-string value expected [InvalidArgument]
assertions_non_falsy_string_false_guard.php:42: Argument 1 of Conformance\Tests\AssertionsNonFalsyStringFalseGuard\takesNonEmptyString cannot be false, non-empty-string value expected [InvalidArgument]
  • Recognition: spelling resolved
  • Enforcement: 2/3 of the expected violations reported

Source

<?php

declare(strict_types=1);

namespace Conformance\Tests\AssertionsNonFalsyStringFalseGuard;

/**
 * `!== false` narrowing with non-falsy-string|false.
 *
 * References:
 * - Psalm scalar string refinements
 * - PHPStan string refinement docs // E?: some tools misparse reference text mentioning non-falsy-string
 * - common analyzer narrowing on false checks
 */

/**
 * @param non-falsy-string $value
 */
function takesNonFalsyString(string $value): void // T: non-falsy-string
{
}

/**
 * @param non-empty-string $value
 */
function takesNonEmptyString(string $value): void // T: non-empty-string
{
}

/**
 * @param non-falsy-string|false $value
 */
function inspectNonFalsyStringOrFalse($value): void // T: non-falsy-string|false
{
    if ($value !== false) {
        takesNonFalsyString($value); // V
        takesNonEmptyString($value); // V
        return;
    }

    takesNonFalsyString($value); // E?: false branch should not expose non-falsy-string
    takesNonEmptyString($value); // E?: false branch should not expose non-empty-string
}