From 78cfcc18e88bbec22f67428eb9add726b4af439a Mon Sep 17 00:00:00 2001 From: Alexander Kucheryuk <3331946+alexkuc@users.noreply.github.com> Date: Wed, 14 Jul 2021 22:04:26 +0300 Subject: [PATCH] Update README.md to explain how to compare enums --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 1e4d1ff..5c3df21 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,29 @@ final class Action extends Enum } ``` +## Comparison + +```php +// returns false +if ($action === Action::VIEW()) { + // ... +} +``` + +```php +// returns true +if ($action == Action::VIEW()) { + // ... +} + +// true +if ($action->equals(Action::VIEW())) { + // ... +} +``` + +php-enums are not singletons so when doing strict comparison, you are comparing equality of _objects_, not values. + ## Related projects - [Doctrine enum mapping](https://github.com/acelaya/doctrine-enum-type)