However, I need to know if it’s possible to do something similar with constants, specifically class constants, and if so, how do you do it?
Basically, we have a class that has a load of constants predefined. A value is passed to one of the methods and depending on the value, I would like it to be substituted for one of the constants. Is this feasible or do I need to change the constants to properties?
If you want an opinion, I wouldn’t do such trickery with constants. I think most people who later read the code, would say wtf.
Edit- I read hastily and misunderstood what you were doing. I thought you had found a way to define then dynamically. You’re just reading them. I think that’s ok.
Oh good, thanks. I thought I’d just committed a cardinal-sin-of-PHP I tried a few alternative ways of doing this and I didn’t like them, and this seemed like the ideal solution, but I couldn’t figure out how to do it until after Immerse’s original post. Good to know that we came up with the same ideas