Skip to content

Commit ec26a00

Browse files
committed
Symbol discovery - fixed looking for functions returning references
1 parent 0f64ca7 commit ec26a00

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ private function findSymbols(string $file): array
226226

227227
preg_match_all('{
228228
(?:
229-
\b(?<![\$:>])(?P<type>class|interface|trait|function) \s++ (?P<name>[a-zA-Z_\x7f-\xff:][a-zA-Z0-9_\x7f-\xff:\-]*+)
229+
\b(?<![\$:>])(?P<type>class|interface|trait|function) \s++ (?P<byref>&\s*)? (?P<name>[a-zA-Z_\x7f-\xff:][a-zA-Z0-9_\x7f-\xff:\-]*+)
230230
| \b(?<![\$:>])(?P<ns>namespace) (?P<nsname>\s++[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\s*+\\\\\s*+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)*+)? \s*+ [\{;]
231231
)
232232
}ix', $contents, $matches);

tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocatorTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ public function dataFunctionExists(): array
8181
'doBaz',
8282
'b.php',
8383
],
84+
[
85+
'get_smarty',
86+
'get_smarty',
87+
'b.php',
88+
],
89+
[
90+
'get_smarty2',
91+
'get_smarty2',
92+
'b.php',
93+
],
8494
];
8595
}
8696

tests/PHPStan/Reflection/BetterReflection/SourceLocator/data/directory/b.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,17 @@ function doBaz()
1919
{
2020

2121
}
22+
23+
function &get_smarty()
24+
{
25+
global $smarty;
26+
27+
return $smarty;
28+
}
29+
30+
function & get_smarty2()
31+
{
32+
global $smarty;
33+
34+
return $smarty;
35+
}

0 commit comments

Comments
 (0)