False warning "Variable '$foo' is undefined" when a variable is defined passing it by reference (preg_match_all)
Describe the bug
When calling
preg_match_all($pattern, $string, $matches),
...the third parameter stores the matches, but PDT signals the parameter as "Variable '$matches' is undefined", and after the statement, it is still considered as undefined, even if it should be considered defined from the call.
Describe the eclipse environment Eclipse 2020-06, PDT 7.2
Describe your system
- OS: Windows
To Reproduce Steps to reproduce the behavior:
- Open a PHP file which calls a function which accepts passing by reference such as preg_match_all(). For example, Parsedown.php.
- Hover over the yellow warning
Expected behavior No warning on the call. PDT should understand that the call defines the variable, or if it can't, warn that such warnings are unreliable.
Screenshots
Additional context The technical issue blocking resolution of this bug is tracked in ticket #532891.
Credits Thanks to Ioan Costescu for writing the initial report of this bug, against PDT 6.0.0.
This issue is still present.
Here is a test that can be added to validate whether it is fixed or not:
new file mode 100644
index 000000000..8c67d548d
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/errors/php5/parameterPassedByReference.pdtt
@@ -0,0 +1,8 @@
+--TEST--
+Parameter passed by reference
+--FILE--
+<?php
+$pattern = '/\d+/';
+\preg_match($pattern, $subject, $matches);
+--EXPECT--
+[line=3, start=48, end=56] Variable '$subject' is undefined
The test result is currently
EXPECTED:
--------------
[line=3, start=48, end=56] Variable '$subject' is undefined*****
ACTUAL:
--------------
[line=3, start=48, end=56] Variable '$subject' is undefined*****
[line=3, start=58, end=66] Variable '$matches' is undefined
This is completely different case, it require lookup into method definition