pdt icon indicating copy to clipboard operation
pdt copied to clipboard

False warning "Variable '$foo' is undefined" when a variable is defined passing it by reference (preg_match_all)

Open Chealer opened this issue 5 years ago • 2 comments

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:

  1. Open a PHP file which calls a function which accepts passing by reference such as preg_match_all(). For example, Parsedown.php.
  2. 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 PDT

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.

Chealer avatar Jul 26 '20 01:07 Chealer

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

cedric-anne avatar Sep 10 '25 09:09 cedric-anne

This is completely different case, it require lookup into method definition

zulus avatar Sep 10 '25 09:09 zulus