Menu

← Back to function.*

Error Identifier: function.strict

Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.

Code example #

<?php declare(strict_types = 1);

function findItem(string $needle, array $haystack): bool
{
	return in_array($needle, $haystack);
}

This rule is provided by the package phpstan/phpstan-strict-rules.

Why is it reported? #

Certain PHP functions perform loose comparison by default, which can lead to unexpected results due to type juggling. The strict rules package requires the strict comparison parameter to be explicitly set to true for the following functions:

  • in_array() – parameter #3 ($strict)
  • array_search() – parameter #3 ($strict)
  • array_keys() – parameter #3 ($strict), when searching for a value
  • base64_decode() – parameter #2 ($strict)

Without strict mode, in_array(0, ['foo']) returns true because 0 == 'foo' under loose comparison. This is almost never the intended behaviour.

How to fix it #

Pass true as the strict comparison parameter:

 <?php declare(strict_types = 1);
 
 function findItem(string $needle, array $haystack): bool
 {
-	return in_array($needle, $haystack);
+	return in_array($needle, $haystack, true);
 }

The same applies to array_search():

 <?php declare(strict_types = 1);
 
 /** @param array<string, mixed> $data */
 function findKey(mixed $value, array $data): string|false
 {
-	return array_search($value, $data);
+	return array_search($value, $data, true);
 }

How to ignore this error #

You can use the identifier function.strict to ignore this error using a comment:

// @phpstan-ignore function.strict
codeThatProducesTheError();

You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:

parameters:
	ignoreErrors:
		-
			identifier: function.strict

Rules that report this error #

  • PHPStan\Rules\StrictCalls\StrictFunctionCallsRule [1] [2] phpstan/phpstan-strict-rules

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.