Skip to content

fix(BinaryExpressionResolver): null coalesce on undefined variable#3031

Merged
dantleech merged 1 commit intophpactor:masterfrom
przepompownia:undef-null-coal
Mar 21, 2026
Merged

fix(BinaryExpressionResolver): null coalesce on undefined variable#3031
dantleech merged 1 commit intophpactor:masterfrom
przepompownia:undef-null-coal

Conversation

@przepompownia
Copy link
Copy Markdown
Contributor

@przepompownia przepompownia commented Mar 10, 2026

Fix: #3030

In practice:

  • it fixes hover info on $baz from the test case
  • diagnostic provider still complains about undefined variable (apparently it's a separate issue).

@przepompownia
Copy link
Copy Markdown
Contributor Author

Image Image

while on master:
Image

@przepompownia przepompownia changed the title fix (BinaryExpressionResolver): null coalesce on undefined variable fix(BinaryExpressionResolver): null coalesce on undefined variable Mar 10, 2026
@dantleech
Copy link
Copy Markdown
Collaborator

in the screen shot it complains that $undef is undefined - is that not correct?

@mamazu
Copy link
Copy Markdown
Contributor

mamazu commented Mar 11, 2026

This makes sense, php (when prod mode is on) just prefills undefined variables with null and the expression will evaluate to an empty array. I don't think that getting rid of the diagnostic is a good idea though.

@przepompownia
Copy link
Copy Markdown
Contributor Author

przepompownia commented Mar 11, 2026

In this case, the code is correct. The complaint is more about potentially bad practice – perhaps it should be shown as a warning (to fix somewhere else).

https://github.com/php/php-src/blob/c658d3c7876ed0269c6b9aef78ff37afa2496145/tests/lang/operators/coalesce.phpt#L27

@dantleech
Copy link
Copy Markdown
Collaborator

happy for the diagnostic to be changed to a warning

@dantleech dantleech force-pushed the undef-null-coal branch 2 times, most recently from 8dd8348 to b21d9d3 Compare March 21, 2026 16:42
@przepompownia
Copy link
Copy Markdown
Contributor Author

przepompownia commented Mar 21, 2026

@dantleech I guess you test benchmark here and we probably did the rebase at almost the same time :)

@dantleech dantleech merged commit 77543fa into phpactor:master Mar 21, 2026
11 checks passed
@przepompownia przepompownia deleted the undef-null-coal branch March 22, 2026 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot recognize value of null-coalesced undefined variable

3 participants