Skip to content

Commit c098fc8

Browse files
schlndhondrejmirtes
authored andcommitted
remove fake params from setcookie/setrawcookie
1 parent 85fcd5f commit c098fc8

File tree

3 files changed

+66
-4
lines changed

3 files changed

+66
-4
lines changed

resources/functionMap.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10424,15 +10424,15 @@
1042410424
'set_include_path' => ['string|false', 'new_include_path'=>'string'],
1042510425
'set_magic_quotes_runtime' => ['bool', 'new_setting'=>'bool'],
1042610426
'set_time_limit' => ['bool', 'seconds'=>'int'],
10427-
'setcookie' => ['bool', 'name'=>'string', 'value='=>'string', 'expires='=>'int', 'path='=>'string', 'domain='=>'string', 'secure='=>'bool', 'httponly='=>'bool', 'samesite='=>'\'None\'|\'Lax\'|\'Strict\'|\'none\'|\'lax\'|\'strict\'', 'url_encode='=>'int'],
10428-
'setcookie\'1' => ['bool', 'name'=>'string', 'value='=>'string', 'options='=>'array{ expires?:int, path?:string, domain?:string, secure?:bool, httponly?:bool, samesite?:\'None\'|\'Lax\'|\'Strict\'|\'none\'|\'lax\'|\'strict\', url_encode?:int}'],
10427+
'setcookie' => ['bool', 'name'=>'string', 'value='=>'string', 'expires='=>'int', 'path='=>'string', 'domain='=>'string', 'secure='=>'bool', 'httponly='=>'bool'],
10428+
'setcookie\'1' => ['bool', 'name'=>'string', 'value='=>'string', 'options='=>'array{ expires?:int, path?:string, domain?:string, secure?:bool, httponly?:bool, samesite?:\'None\'|\'Lax\'|\'Strict\'|\'none\'|\'lax\'|\'strict\'}'],
1042910429
'setLeftFill' => ['void', 'red'=>'int', 'green'=>'int', 'blue'=>'int', 'a='=>'int'],
1043010430
'setLine' => ['void', 'width'=>'int', 'red'=>'int', 'green'=>'int', 'blue'=>'int', 'a='=>'int'],
1043110431
'setlocale' => ['string|false', 'category'=>'int', 'locale'=>'string|null', '...args='=>'string'],
1043210432
'setlocale\'1' => ['string|false', 'category'=>'int', 'locale'=>'?array'],
1043310433
'setproctitle' => ['void', 'title'=>'string'],
10434-
'setrawcookie' => ['bool', 'name'=>'string', 'value='=>'string', 'expires='=>'int', 'path='=>'string', 'domain='=>'string', 'secure='=>'bool', 'httponly='=>'bool', 'samesite='=>'\'None\'|\'Lax\'|\'Strict\'|\'none\'|\'lax\'|\'strict\'', 'url_encode='=>'int'],
10435-
'setrawcookie\'1' => ['bool', 'name'=>'string', 'value='=>'string', 'options='=>'array{ expires?:int, path?:string, domain?:string, secure?:bool, httponly?:bool, samesite?:\'None\'|\'Lax\'|\'Strict\'|\'none\'|\'lax\'|\'strict\', url_encode?:int}'],
10434+
'setrawcookie' => ['bool', 'name'=>'string', 'value='=>'string', 'expires='=>'int', 'path='=>'string', 'domain='=>'string', 'secure='=>'bool', 'httponly='=>'bool'],
10435+
'setrawcookie\'1' => ['bool', 'name'=>'string', 'value='=>'string', 'options='=>'array{ expires?:int, path?:string, domain?:string, secure?:bool, httponly?:bool, samesite?:\'None\'|\'Lax\'|\'Strict\'|\'none\'|\'lax\'|\'strict\'}'],
1043610436
'setRightFill' => ['void', 'red'=>'int', 'green'=>'int', 'blue'=>'int', 'a='=>'int'],
1043710437
'setthreadtitle' => ['bool', 'title'=>'string'],
1043810438
'settype' => ['bool', '&rw_var'=>'mixed', 'type'=>'string'],

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,4 +1558,30 @@ public function testCallToArrayFilterWithNullCallback(): void
15581558
$this->analyse([__DIR__ . '/data/array_filter_null_callback.php'], []);
15591559
}
15601560

1561+
public function testBug10171(): void
1562+
{
1563+
if (PHP_VERSION_ID < 80000) {
1564+
$this->markTestSkipped('Test requires PHP 8.0');
1565+
}
1566+
1567+
$this->analyse([__DIR__ . '/data/bug-10171.php'], [
1568+
[
1569+
'Unknown parameter $samesite in call to function setcookie.',
1570+
12,
1571+
],
1572+
[
1573+
'Function setcookie invoked with 9 parameters, 1-7 required.',
1574+
13,
1575+
],
1576+
[
1577+
'Unknown parameter $samesite in call to function setrawcookie.',
1578+
25,
1579+
],
1580+
[
1581+
'Function setrawcookie invoked with 9 parameters, 1-7 required.',
1582+
26,
1583+
],
1584+
]);
1585+
}
1586+
15611587
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php declare(strict_types=1); // lint >= 8.0
2+
3+
namespace Bug10171;
4+
5+
setcookie("name", "value", 0, "/", secure: true, httponly: true);
6+
setcookie('name', expires_or_options: ['samesite' => 'lax']);
7+
8+
setrawcookie("name", "value", 0, "/", secure: true, httponly: true);
9+
setrawcookie('name', expires_or_options: ['samesite' => 'lax']);
10+
11+
// Wrong
12+
setcookie('name', samesite: 'lax');
13+
setcookie(
14+
'aaa',
15+
'bbb',
16+
10,
17+
'/',
18+
'example.com',
19+
true,
20+
false,
21+
'lax',
22+
1,
23+
);
24+
25+
setrawcookie('name', samesite: 'lax');
26+
setrawcookie(
27+
'aaa',
28+
'bbb',
29+
10,
30+
'/',
31+
'example.com',
32+
true,
33+
false,
34+
'lax',
35+
1,
36+
);

0 commit comments

Comments
 (0)