Yii2 Status Properties - Why? Best Practice?

I’ve been pondering why the developers use 0, 10 as statuses for the User model rather than 0, 1 or whathaveyou.

This let me to think about the status property as a whole and then made me question what the different (ideal?) implementations there are and which one is best for what purposes.

I generally use the following status states using the User status property as a base:




So… Was it done because of the desire to support bit-based enums? 1 vs 10 vs 01 vs 100 vs … ?? Or was it done to avoid supporting boolean type as a status?

What is everyone’s thoughts on this? I don’t see any convention or definition for them and am rather interested in possibly defining a gold standard for use of status properties for models as a whole.

I think every developer or project has it’s own conventions for this. The number one issue (for me) is to avoid values clashing with other status values. So for example you have ACTIVE = 1, but a different class (model or anything else) maybe that wants to set the status DRAFT which (because it’s written by a diffrent developer, for a diffrent purpose or it’s a class reused form a different project) it also has the value 1.

That’s why I like keywords in clojure, the value of the keyword :active is :active for this reason I started using strings as status values for projects that switch to and from different statuses.

Great points. In some cases, string-based statuses are used in some of my projects but I still can’t help but think there’s a better, or more logical way. What about when you have composite statues - eg. INACTIVE vs ACTIVE-DRAFT, ACTIVE-FINAL? In those cases, bitwise status properties might make more sense!

In cases where string is key, you can use enums in mysql (and some other dbms) and constants for statuses but there is still the possibility of translations, typos, etc. and also considering lack of direct support from frameworks and/or dbms such as Yii.