Skip to content

Commit 3d2cab7

Browse files
Restrict chr param for PHP 8.5+
1 parent 6818997 commit 3d2cab7

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php // phpcs:ignoreFile
2+
3+
/**
4+
* This contains the information needed to convert the function signatures for php 8.5 to php 8.4 (and vice versa)
5+
*
6+
* This has two sections.
7+
* The 'new' section contains function/method names from FunctionSignatureMap (And alternates, if applicable) that do not exist in php8.4 or have different signatures in php 8.5.
8+
* If they were just updated, the function/method will be present in the 'added' signatures.
9+
* The 'old' signatures contains the signatures that are different in php 8.4.
10+
* Functions are expected to be removed only in major releases of php.
11+
*
12+
* @see FunctionSignatureMap.php
13+
*
14+
* @phan-file-suppress PhanPluginMixedKeyNoKey (read by Phan when analyzing this file)
15+
*/
16+
return [
17+
'new' => [
18+
'chr' => ['non-empty-string', 'ascii'=>'int<0,255>'],
19+
],
20+
'old' => [
21+
'chr' => ['non-empty-string', 'ascii'=>'int'],
22+
]
23+
];

src/Reflection/SignatureMap/FunctionSignatureMapProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ public function getSignatureMap(): array
219219
$signatureMap = $this->computeSignatureMapFile($signatureMap, __DIR__ . '/../../../resources/functionMap_php84delta.php');
220220
}
221221

222+
if ($this->phpVersion->getVersionId() >= 80500) {
223+
$signatureMap = $this->computeSignatureMapFile($signatureMap, __DIR__ . '/../../../resources/functionMap_php85delta.php');
224+
}
225+
222226
return self::$signatureMaps[$cacheKey] = $signatureMap;
223227
}
224228

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2505,6 +2505,17 @@ public function testClone(): void
25052505
]);
25062506
}
25072507

2508+
#[RequiresPhp('>= 8.5')]
2509+
public function testBug13930(): void
2510+
{
2511+
$this->analyse([__DIR__ . '/data/bug-13930.php'], [
2512+
[
2513+
'Parameter #1 $codepoint of function chr expects int<0, 255>, 256 given.',
2514+
9,
2515+
],
2516+
]);
2517+
}
2518+
25082519
#[RequiresPhp('>= 8.1')]
25092520
public function testBug13862(): void
25102521
{
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug13930;
4+
5+
class HelloWorld
6+
{
7+
public function sayHello() : void
8+
{
9+
var_dump(chr(256));
10+
}
11+
}

0 commit comments

Comments
 (0)