apache / apache/netbeans

[PHP] Comparing enum case might produce warning

Open
#5,088 0 comments 0 reactions 0 assignees View on GitHub
kind:feature PHP
Dominant language
Java
Stars
3.1k
Forks
935
Avg merge
2d 3h
Merged PRs (30d)
17

Description

### Apache NetBeans version

Apache NetBeans 16

### What happened

Since comparing enum case are not meaningful (always return false), it should produce warning.

### How to reproduce

```php
Suit::Diamonds); // bool(false)
var_dump(Suit::Hearts < Suit::Diamonds); // bool(false)

// common construct, $card1 & $card2 can be any asignment of enum case
if ($card1 == $card2) {} // OK
if ($card1 === $card2) {} // OK
if ($card1->value == $card2->value) {} // OK
if ($card1->value === $card2->value) {} // OK
if ($card1 > $card2) {} // this statement should display warning
if ($card1->value > $card2->value) {} // OK

// common construct, $mixed can be any value other than enum case
if ($card1 == $mixed) {} // this statement should display warning
if ($card1 === $mixed) {} // this statement should display warning
if ($card1->value == $mixed) {} // OK
if ($card1->value === $mixed) {} // OK
if ($card1 > $mixed) {} // this statement should display warning
if ($card1->value > $mixed) {} // OK

// rare construct, less relevant
if (Suit::Hearts == Suit::Diamonds) {} // this statement should display warning
if (Suit::Hearts === Suit::Diamonds) {} // this statement should display warning
if (Suit::Hearts > Suit::Diamonds) {} // this statement should display warning
if (Suit::Hearts->value > Suit::Diamonds->value) {} // OK
```

### Did this work correctly in an earlier version?

No / Don't know

### Operating System

Windows 10

### JDK

Java: 14.0.1; Java HotSpot(TM) 64-Bit Server VM 14.0.1+7 Runtime: Java(TM) SE Runtime Environment 14.0.1+7

### Apache NetBeans packaging

Apache NetBeans provided installer

### Anything else

_No response_

### Are you willing to submit a pull request?

No

### Code of Conduct

Yes

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the supplied enum-comparison examples in Apache NetBeans 16 and locate the PHP editor's diagnostic behavior for those expressions. Done means warnings appear for comparisons involving enum cases or other non-enum values where requested, while comparisons through ->value remain without warnings.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.