Skip to content

Commit 4b3a9d5

Browse files
Fix password_hash return type
1 parent 606bcbf commit 4b3a9d5

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

resources/functionMap.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8249,7 +8249,7 @@
82498249
'parsekit_func_arginfo' => ['array', 'function'=>'mixed'],
82508250
'passthru' => ['void', 'command'=>'string', '&w_return_value='=>'int'],
82518251
'password_get_info' => ['array', 'hash'=>'string'],
8252-
'password_hash' => ['non-empty-string|false', 'password'=>'string', 'algo'=>'int', 'options='=>'array'],
8252+
'password_hash' => ['__benevolent<non-empty-string|false|null>', 'password'=>'string', 'algo'=>'int', 'options='=>'array'],
82538253
'password_make_salt' => ['bool', 'password'=>'string', 'hash'=>'string'],
82548254
'password_needs_rehash' => ['bool', 'hash'=>'string', 'algo'=>'int', 'options='=>'array'],
82558255
'password_verify' => ['bool', 'password'=>'string', 'hash'=>'string'],

resources/functionMap_php74delta.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
'get_mangled_object_vars' => ['array', 'obj'=>'object'],
4242
'mb_str_split' => ['list<string>|false', 'str'=>'string', 'split_length='=>'int', 'encoding='=>'string'],
4343
'password_algos' => ['list<string>'],
44-
'password_hash' => ['string|false', 'password'=>'string', 'algo'=>'string|null', 'options='=>'array'],
44+
'password_hash' => ['__benevolent<string|false|null>', 'password'=>'string', 'algo'=>'string|null', 'options='=>'array'],
4545
'password_needs_rehash' => ['bool', 'hash'=>'string', 'algo'=>'string|null', 'options='=>'array'],
4646
'preg_replace_callback' => ['string|array|null', 'regex'=>'string|array', 'callback'=>'callable(array<int|string, string>):string', 'subject'=>'string|array', 'limit='=>'int', '&w_count='=>'int', 'flags='=>'int'],
4747
'preg_replace_callback_array' => ['string|array|null', 'pattern'=>'array<string,callable>', 'subject'=>'string|array', 'limit='=>'int', '&w_count='=>'int', 'flags='=>'int'],

tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php

+21
Original file line numberDiff line numberDiff line change
@@ -882,4 +882,25 @@ public function testBug8776Part2(): void
882882
$this->analyse([__DIR__ . '/data/bug-8776-2.php'], []);
883883
}
884884

885+
public function testBug5978(): void
886+
{
887+
if (PHP_VERSION_ID >= 80000) {
888+
$expectedErrors = [
889+
[
890+
'Strict comparison using === between string and false will always evaluate to false.',
891+
7,
892+
],
893+
[
894+
'Strict comparison using === between string and null will always evaluate to false.',
895+
7,
896+
],
897+
];
898+
} else {
899+
$expectedErrors = [];
900+
}
901+
902+
$this->checkAlwaysTrueStrictComparison = true;
903+
$this->analyse([__DIR__ . '/data/bug-5978.php'], $expectedErrors);
904+
}
905+
885906
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug5969;
4+
5+
function hash(string $input) : string {
6+
$hash = password_hash($input, PASSWORD_DEFAULT);
7+
if ($hash === false || $hash === null) {
8+
throw new \Exception("Could not generate hash");
9+
}
10+
11+
return $hash;
12+
}

0 commit comments

Comments
 (0)