note 128380 added to language.enumerations.overview
| From: | HayleyWatson at main dot php dot net | Date: | Sun, 09 Apr 2023 01:06:55 +0000 |
| Subject: | note 128380 added to language.enumerations.overview | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220335@lists.php.net to get a copy of this message | ||
It's important to notice that the description here doesn't describe Enum values as being
constants. Some languages, like C, C++, and C#, think of an enum as a list of named integers, and
working with enums in those languages is just working with integers. PHP does not do that.
In the same way that PHP's booleans are their own type and not just constants with integer
values 1 and 0, an Enum is its own type. It's not a bunch of integers (or strings) that have
been given names, and shouldn't be thought of or used as such.
An Enum only needs to be backed by some primitive value like an integer or string if you need to
communicate it outside the program (a message, UI, db storage, wire protocol, etc) where it has to
be converted from/to its native PHP value (this is addressed again on the Backed Enumerations page).
If you're converting back and forth between Enums and their backing values inside your own
program to get anything done then you might be missing the point of Enums.
You might want more structure to your Enum than just a pure set of distinct but otherwise
nondescript values (you might at least want them to be ordered). But all that carry-on should be
encapsulated within the Enum class itself via additional methods.
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.13.130 (proxied: 125.239.194.160)
----
Manual Page -- https://php.net/manual/en/language.enumerations.overview.php
Edit -- https://main.php.net/note/edit/128380
Del: integrated -- https://main.php.net/note/delete/128380/integrated
Del: useless -- https://main.php.net/note/delete/128380/useless
Del: bad code -- https://main.php.net/note/delete/128380/bad+code
Del: spam -- https://main.php.net/note/delete/128380/spam
Del: non-english -- https://main.php.net/note/delete/128380/non-english
Del: in docs -- https://main.php.net/note/delete/128380/in+docs
Del: other reasons-- https://main.php.net/note/delete/128380
Reject -- https://main.php.net/note/reject/128380
Search -- https://main.php.net/manage/user-notes.php