Jump to content

maccieD

New Members
  • Posts

    3
  • Joined

  • Last visited

maccieD's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. This is exactly what I'm struggling with, I resorted to the "text-book" answer in that everything should be enums and ideally non-backed. But I guess I am overthinking it in terms of performance. I even set up 2 tests, one that simply echoed a class constant and one that echoed a enum class value: Class constant (simple class with 8 constants, 4 properties, 11 methods, 174 lines of code): average load/execution time (over 5 runs) - 0.5162 ms. Enum class value (enum with 5 backed cases): average load/execution time (over 5 runs): 0.2928ms Were talking about half and 0.2 millisecond here!
  2. Doesn't that defeat the point? We're back to using literals for indicies, you have to know that [3] is a compliment. Also, you now have the overhead of reading an "external" file? Yes I know that the enum is a class that has to be loaded, but surely there's a chance in its in the opcache unlike the ini file?
  3. I'm doing the conversion of my codebase from PHP 7.2 to 8.2 and trying to take advantage of any new features i can. I like the idea of using enums as I've always disliked having to load/parse a whole class just to access (for example) only 1 constant. However, I'm struggling with the structure of the enum files. I currently have a simple class Contact which has constants for the state ACTIONED and UNACTIONED. When someone makes a contact I have constants in the same class for the contact type TYPE_QUERY, TYPE_SUGGESTION, TYPE_COMPLIMENT etc. In this simple example, an enum equivalent would be: ContactState (Actioned/Unactioned) and an enum class for ContactType (Query,Suggestion, Compliment). Would this be right? It's just seems a little overkill having 2 files and 1 of them having just 2 values in it?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.