Skip to content

Commit 72e37dc

Browse files
committed
Fix session_set_cookie_params call with named arguments
1 parent 043a14c commit 72e37dc

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

src/Analyser/ArgumentsNormalizer.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use function count;
1919
use function ksort;
2020
use function max;
21+
use function sprintf;
2122

2223
/**
2324
* @api
@@ -276,7 +277,7 @@ public static function reorderArgs(ParametersAcceptor $parametersAcceptor, array
276277
$defaultValue = $parameter->getDefaultValue();
277278
if ($defaultValue === null) {
278279
if (!$parameter->isVariadic()) {
279-
throw new ShouldNotHappenException('An optional parameter must have a default value');
280+
throw new ShouldNotHappenException(sprintf('An optional parameter $%s must have a default value', $parameter->getName()));
280281
}
281282
$defaultValue = new ConstantArrayType([], []);
282283
}

src/Reflection/SignatureMap/Php8SignatureMapProvider.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ private function getMergedSignatures(FunctionSignature $nativeSignature, array $
272272
$functionParam->getNativeType(),
273273
$functionParam->passedByReference(),
274274
$functionParam->isVariadic(),
275-
$functionParam->getDefaultValue(),
276-
$functionParam->getOutType(),
275+
$functionParam->getDefaultValue() ?? $nativeParam->getDefaultValue(),
276+
$functionParam->getOutType() ?? $nativeParam->getOutType(),
277277
);
278278
}
279279

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,16 @@ public function testBug8147(): void
11381138
$this->assertNoErrors($errors);
11391139
}
11401140

1141+
public function testBug12934(): void
1142+
{
1143+
if (PHP_VERSION_ID < 80000) {
1144+
$this->markTestSkipped('Test requires PHP 8.0.');
1145+
}
1146+
1147+
$errors = $this->runAnalyse(__DIR__ . '/data/bug-12934.php');
1148+
$this->assertNoErrors($errors);
1149+
}
1150+
11411151
public function testConditionalExpressionInfiniteLoop(): void
11421152
{
11431153
$errors = $this->runAnalyse(__DIR__ . '/data/conditional-expression-infinite-loop.php');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php // lint >= 8.0
2+
3+
declare(strict_types = 1);
4+
5+
namespace Bug12934;
6+
7+
function(string $path): void {
8+
session_set_cookie_params(0, path: $path, secure: true, httponly: true);
9+
};

0 commit comments

Comments
 (0)