Skip to content

Commit a4980e1

Browse files
committed
1 parent 7697398 commit a4980e1

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,4 +878,24 @@ public function testBug11572(): void
878878
]);
879879
}
880880

881+
public function testBug2313(): void
882+
{
883+
$this->analyse([__DIR__ . '/data/bug-2313.php'], []);
884+
}
885+
886+
public function testBug11655(): void
887+
{
888+
$this->analyse([__DIR__ . '/data/bug-11655.php'], [
889+
[
890+
"Offset 3 does not exist on array{string, 'x', array{string, 'x'}}.",
891+
15,
892+
],
893+
]);
894+
}
895+
896+
public function testBug2634(): void
897+
{
898+
$this->analyse([__DIR__ . '/data/bug-2634.php'], []);
899+
}
900+
881901
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Bug11655;
4+
5+
class Foo
6+
{
7+
public function test(string $v): string
8+
{
9+
if (preg_match('~a(x)~', $v, $matches) === 1) {
10+
if (preg_match('~b(x)~', $v, $matches[2]) === 1) {
11+
return $matches[2][1];
12+
}
13+
14+
if (preg_match('~c(x)~', $v, $matches[2]) === 1) {
15+
return $matches[3][1];
16+
}
17+
18+
return $matches[1];
19+
}
20+
21+
return 'n/a';
22+
}
23+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Bug2313;
4+
5+
function safe_inc(&$variable, $increment=1) {
6+
if (isset($variable)) {
7+
$variable += $increment;
8+
} else {
9+
$variable = $increment;
10+
}
11+
return true;
12+
}
13+
14+
function (): void {
15+
$data = array('apples' => array());
16+
17+
safe_inc($data['apples']['count']);
18+
print_r($data);
19+
20+
safe_inc($data['apples']['count']);
21+
print_r($data);
22+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Bug2634;
4+
5+
function hi(&$thing){
6+
$thing = "hi";
7+
}
8+
9+
function (): void {
10+
$array = [];
11+
12+
hi($array["hi"]);
13+
};

0 commit comments

Comments
 (0)