@@ -153,6 +153,13 @@ class VariableAnalysisSniff implements Sniff
153
153
*/
154
154
public $ allowUnusedVariablesBeforeRequire = false ;
155
155
156
+ /**
157
+ * A cache for getPassByReferenceFunctions
158
+ *
159
+ * @var array<array<int|string>>
160
+ */
161
+ private $ passByRefFunctionsCache = [];
162
+
156
163
public function __construct ()
157
164
{
158
165
$ this ->scopeManager = new ScopeManager ();
@@ -195,6 +202,18 @@ public function register()
195
202
*/
196
203
private function getPassByReferenceFunction ($ functionName )
197
204
{
205
+ $ passByRefFunctions = $ this ->getPassByReferenceFunctions ();
206
+ return isset ($ passByRefFunctions [$ functionName ]) ? $ passByRefFunctions [$ functionName ] : [];
207
+ }
208
+
209
+ /**
210
+ * @return array<array<int|string>>
211
+ */
212
+ private function getPassByReferenceFunctions ()
213
+ {
214
+ if ($ this ->passByRefFunctionsCache ) {
215
+ return $ this ->passByRefFunctionsCache ;
216
+ }
198
217
$ passByRefFunctions = Constants::getPassByReferenceFunctions ();
199
218
if (!empty ($ this ->sitePassByRefFunctions )) {
200
219
$ lines = Helpers::splitStringToArray ('/\s+/ ' , trim ($ this ->sitePassByRefFunctions ));
@@ -206,7 +225,8 @@ private function getPassByReferenceFunction($functionName)
206
225
if ($ this ->allowWordPressPassByRefFunctions ) {
207
226
$ passByRefFunctions = array_merge ($ passByRefFunctions , Constants::getWordPressPassByReferenceFunctions ());
208
227
}
209
- return isset ($ passByRefFunctions [$ functionName ]) ? $ passByRefFunctions [$ functionName ] : [];
228
+ $ this ->passByRefFunctionsCache = $ passByRefFunctions ;
229
+ return $ passByRefFunctions ;
210
230
}
211
231
212
232
/**
@@ -1485,7 +1505,12 @@ protected function processVariableAsPassByReferenceFunctionCall(File $phpcsFile,
1485
1505
$ functionName = $ tokens [$ functionPtr ]['content ' ];
1486
1506
$ refArgs = $ this ->getPassByReferenceFunction ($ functionName );
1487
1507
if (! $ refArgs ) {
1488
- return false ;
1508
+ // Check again with the fully namespaced function name.
1509
+ $ functionName = Helpers::getFunctionNameWithNamespace ($ phpcsFile , $ functionPtr );
1510
+ $ refArgs = $ this ->getPassByReferenceFunction ($ functionName );
1511
+ if (! $ refArgs ) {
1512
+ return false ;
1513
+ }
1489
1514
}
1490
1515
1491
1516
$ argPtrs = Helpers::findFunctionCallArguments ($ phpcsFile , $ stackPtr );
0 commit comments