Suppose I have a function called checkTemperature($temp) that can return three different possibilities:
- too hot
- OK
- too cold
Would you return integers, such as -1, 0, 1 or 1, 2, 3 (etc..) or strings, such as the above?
What is considered the best practice?
You would typically use enums, but PHP doesn’t straight up have support for an enum construct. However, we can certainly emulate them.
Then you can do
And compare
The value you assign your variables is not really important, as long as they are different. You can use the values for something interesting depending on your app and context.