Skip to content

Commit 5f4200a

Browse files
phpstan-botclaude
andcommitted
Add function call test cases for bug-14318
Adds regression tests for regular function calls (FuncCallHandler) with variable assignment in arguments, proving this handler already had the correct throw point order. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 770316b commit 5f4200a

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

tests/PHPStan/Rules/Variables/data/bug-14318.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,59 @@ public static function maybeThrows8(int $s): void
113113
}
114114
}
115115
}
116+
117+
/**
118+
* @throws \RuntimeException
119+
*/
120+
function maybeThrows9(string $s): void
121+
{
122+
if (random_int(0, 1) === 1) {
123+
throw new \RuntimeException();
124+
}
125+
}
126+
127+
/**
128+
* @throws \RuntimeException
129+
*/
130+
function maybeThrows10(int $s): void
131+
{
132+
if (random_int(0, 1) === 1) {
133+
throw new \RuntimeException();
134+
}
135+
}
136+
137+
class HelloWorld9
138+
{
139+
public function test9(): void
140+
{
141+
global $pdo;
142+
143+
try {
144+
maybeThrows9($sql = "SELECT * FROM foo");
145+
$rs = $pdo->query($sql);
146+
if ($result = $rs->fetch(\PDO::FETCH_ASSOC)) {
147+
// do something
148+
}
149+
} catch (\PDOException $e) {
150+
var_dump($sql);
151+
}
152+
}
153+
}
154+
155+
class HelloWorld10
156+
{
157+
public function test10(): void
158+
{
159+
global $pdo;
160+
161+
try {
162+
maybeThrows10(strlen($sql = "SELECT * FROM foo"));
163+
$rs = $pdo->query($sql);
164+
if ($result = $rs->fetch(\PDO::FETCH_ASSOC)) {
165+
// do something
166+
}
167+
} catch (\PDOException $e) {
168+
var_dump($sql);
169+
}
170+
}
171+
}

0 commit comments

Comments
 (0)