Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VarDumper] add support for enums on PHP 8.1 #40238

Closed
nicolas-grekas opened this issue Feb 18, 2021 · 4 comments · Fixed by #40867
Closed

[VarDumper] add support for enums on PHP 8.1 #40238

nicolas-grekas opened this issue Feb 18, 2021 · 4 comments · Fixed by #40867
Labels
Help wanted Issues and PRs which are looking for volunteers to complete them. VarDumper

Comments

@nicolas-grekas
Copy link
Member

https://wiki.php.net/rfc/enumerations

@nicolas-grekas nicolas-grekas added the Help wanted Issues and PRs which are looking for volunteers to complete them. label Feb 18, 2021
@alexandre-daubois
Copy link
Contributor

Hi, enumerations seems to work well with VarDumper. What is the result you expect, if different from the current?

@nicolas-grekas
Copy link
Member Author

Dunno, I didn't try yet :)
What's the current output?

@maxim-dovydenok
Copy link
Contributor

maxim-dovydenok commented Apr 19, 2021

enum UnitEnumFixture {
    case Hearts;
    case Diamonds;
    case Clubs;
    case Spades;
}

dump(UnitEnumFixture::Hearts);
Symfony\Component\VarDumper\Tests\Fixtures\UnitEnumFixture {#435
  +name: "Hearts"
}
enum BackedEnumFixture: string {
    case Hearts = 'H';
    case Diamonds = 'D';
    case Clubs = 'C';
    case Spades = 'S';
}

dump(BackedEnumFixture::Hearts);
Symfony\Component\VarDumper\Tests\Fixtures\BackedEnumFixture {#157
  +name: "Hearts"
  +value: "H"
}

@derrabus
Copy link
Member

That output looks good to me, let's close this issue.

@shiftby: Do you want to submit a PR that adds tests for your two fixture classes, to make sure we don't break VarDumper for enums in the future?

derrabus added a commit that referenced this issue Apr 19, 2021
This PR was merged into the 4.4 branch.

Discussion
----------

[VarDumper] Add PHP 8.1 enums tests

VarDumper component already supports PHP 8.1 enums, but didn't have tests

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #40238
| License       | MIT
| Doc PR        | no

VarDumper component already supports PHP 8.1 enums, but it didn't have tests.

```php
enum UnitEnumFixture {
    case Hearts;
    case Diamonds;
    case Clubs;
    case Spades;
}

dump(UnitEnumFixture::Hearts);
```
```
Symfony\Component\VarDumper\Tests\Fixtures\UnitEnumFixture {#435
  +name: "Hearts"
}
```

```php
enum BackedEnumFixture: string {
    case Hearts = 'H';
    case Diamonds = 'D';
    case Clubs = 'C';
    case Spades = 'S';
}

dump(BackedEnumFixture::Hearts);
```
```
Symfony\Component\VarDumper\Tests\Fixtures\BackedEnumFixture {#157
  +name: "Hearts"
  +value: "H"
}
```

Commits
-------

9a2a027 [VarDumper] Add PHP 8.1 enums tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help wanted Issues and PRs which are looking for volunteers to complete them. VarDumper
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants