@@ -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,20 @@ 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
+ * @param string $functionName
211
+ *
212
+ * @return array<array<int|string>>
213
+ */
214
+ private function getPassByReferenceFunctions ()
215
+ {
216
+ if ($ this ->passByRefFunctionsCache ) {
217
+ return $ this ->passByRefFunctionsCache ;
218
+ }
198
219
$ passByRefFunctions = Constants::getPassByReferenceFunctions ();
199
220
if (!empty ($ this ->sitePassByRefFunctions )) {
200
221
$ lines = Helpers::splitStringToArray ('/\s+/ ' , trim ($ this ->sitePassByRefFunctions ));
@@ -206,7 +227,8 @@ private function getPassByReferenceFunction($functionName)
206
227
if ($ this ->allowWordPressPassByRefFunctions ) {
207
228
$ passByRefFunctions = array_merge ($ passByRefFunctions , Constants::getWordPressPassByReferenceFunctions ());
208
229
}
209
- return isset ($ passByRefFunctions [$ functionName ]) ? $ passByRefFunctions [$ functionName ] : [];
230
+ $ this ->passByRefFunctionsCache = $ passByRefFunctions ;
231
+ return $ passByRefFunctions ;
210
232
}
211
233
212
234
/**
@@ -1485,7 +1507,12 @@ protected function processVariableAsPassByReferenceFunctionCall(File $phpcsFile,
1485
1507
$ functionName = $ tokens [$ functionPtr ]['content ' ];
1486
1508
$ refArgs = $ this ->getPassByReferenceFunction ($ functionName );
1487
1509
if (! $ refArgs ) {
1488
- return false ;
1510
+ // Check again with the fully namespaced function name.
1511
+ $ functionName = Helpers::getFunctionNameWithNamespace ($ phpcsFile , $ functionPtr );
1512
+ $ refArgs = $ this ->getPassByReferenceFunction ($ functionName );
1513
+ if (! $ refArgs ) {
1514
+ return false ;
1515
+ }
1489
1516
}
1490
1517
1491
1518
$ argPtrs = Helpers::findFunctionCallArguments ($ phpcsFile , $ stackPtr );
0 commit comments