You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"Using type hints of "Union Types" or "Intersection Types" such as array|Bar1 or Bar1&Bar2 can cause the highlighting of the entire PHP file to malfunction."
changed the title [-]Not working with type hints of "Union Types"[/-][+]Not working with type hints of "Union Types" and "Intersection Types"[/+]on Feb 20, 2023
@marabesi
With no luck. It seems the problem still exists, even with the use_next_version and ignore_comments flags added.
Furthermore, I have also discovered that "named arguments" can also cause errors.
Both "union types" and "named arguments" are new features of PHP 8.0, so perhaps the PHP Parser version is too old, as PHP Parser 3.1.3 seems to support up to PHP 7.2, while PHP Parser 4.x currently supports PHP 8.x.
Just a small hint on the php-parser version, this library is in typescript so there is no direct connection with the parser from nikita.
This is the correct library: glayzzle/php-parser#486. The PHP version is still under development though.
From the samples you shared it seems that the library is working as expected (see the pipeline with the new test cases added here.
Nevertheless, the example you shared with json_encode seems to be working as expected as well, this is the version I have:
I found an issue when trying to combine the type of parameters though:
But this one will require an update from the library this project is using (I am not sure at the moment).
I am not sure if it is possible to have a union type of array and an optional Bar2. Is it possible?
For the time being what is exactly the outcome you expect from the examples you shared? For me here goes the output:
Example 1: should highlight 2 unused imports - this seems to break in your example
Example 2: should highlight 2 unused imports - this is working without the json function
Thanks for the replies.
Today, I updated the extension from v0.10.0 to v0.10.2, and some issues seem to have been resolved.
The code mentioned above, it seems that everything is functioning properly.
However, there is still an (new?) issue where commented-out code is not being marked as unused imports.
Additionally, the behavior of the ignore_comments option seems to be behaving strangely with both comments and PHPDoc.
Bar4 is commented-out PHPDoc. Bar5 and Bar6 are commented-out codes.
Scene 1: Bar4, Bar5, and Bar6 have been commented-out, but they are still not highlighted as unused imports.
Scene 2:
After adding use_next_version and ignore_comments flags, Bar4 is highlighted as unused, but Bar5 and Bar6 are still not highlighted.
Activity
[-]Not working with type hints of "Union Types"[/-][+]Not working with type hints of "Union Types" and "Intersection Types"[/+]marabesi commentedon Feb 25, 2023
thanks for reporting @bluedasher13
marabesi commentedon Feb 25, 2023
@bluedasher13 does it happens if you use the option next version?
Here goes an example of the setting:
chore: adds test cases related to intersection types
bluedasher13 commentedon Feb 26, 2023
@marabesi
With no luck. It seems the problem still exists, even with the
use_next_version
andignore_comments
flags added.Furthermore, I have also discovered that "named arguments" can also cause errors.
Both "union types" and "named arguments" are new features of PHP 8.0, so perhaps the PHP Parser version is too old, as PHP Parser 3.1.3 seems to support up to PHP 7.2, while PHP Parser 4.x currently supports PHP 8.x.
php-import-checker/package.json
Line 58 in 4e3669a
https://github.com/nikic/PHP-Parser#php-parser
marabesi commentedon Feb 26, 2023
Just a small hint on the php-parser version, this library is in typescript so there is no direct connection with the parser from nikita.
This is the correct library: glayzzle/php-parser#486. The PHP version is still under development though.
From the samples you shared it seems that the library is working as expected (see the pipeline with the new test cases added here.
Nevertheless, the example you shared with json_encode seems to be working as expected as well, this is the version I have:
I found an issue when trying to combine the type of parameters though:
But this one will require an update from the library this project is using (I am not sure at the moment).
I am not sure if it is possible to have a union type of array and an optional Bar2. Is it possible?
For the time being what is exactly the outcome you expect from the examples you shared? For me here goes the output:
Example 1: should highlight 2 unused imports - this seems to break in your example
Example 2: should highlight 2 unused imports - this is working without the json function
chore: adds test cases related to intersection types
bluedasher13 commentedon Mar 1, 2023
Thanks for the replies.
Today, I updated the extension from v0.10.0 to v0.10.2, and some issues seem to have been resolved.
The code mentioned above, it seems that everything is functioning properly.
However, there is still an (new?) issue where commented-out code is not being marked as unused imports.
Additionally, the behavior of the
ignore_comments
option seems to be behaving strangely with both comments and PHPDoc.Bar4
is commented-out PHPDoc.Bar5
andBar6
are commented-out codes.Scene 1:

Bar4
,Bar5
, andBar6
have been commented-out, but they are still not highlighted as unused imports.Scene 2:

After adding use_next_version and ignore_comments flags,
Bar4
is highlighted as unused, butBar5
andBar6
are still not highlighted.marabesi commentedon Mar 4, 2023
@bluedasher13 can you paste there the code you are using instead of printing it? It helps me to adds those as test cases in the pipeline.