Enumeration-a large number of numbers in PHP are used to identify the type or status. what is the optimal solution?

Source: Internet
Author: User
Now we use an ftype field int type in the mysql database table to identify the type. at this time, there are about 20 types. because of the long term, various numbers in the program seem very laborious. How do you deal with such problems in the program? Now the idea is... now we use an ftype field int type in the mysql database table to identify the type. at this time, there are about 20 types. because of the long term, various numbers in the program seem very laborious.

How do you deal with such problems in the program?

Now we are thinking:

  1. Restrict programmers to use numbers to add tags without authorization, and add a class such:

class action{    const EDIT = 0;    const VIEW = 1;    //...}

All must be used by the parameter action class.

2. use the open-source enumeration class on github for implementation.
Such as: https://github.com/myclabs/ph...

Reply content:

Now we use an ftype field int type in the mysql database table to identify the type. at this time, there are about 20 types. because of the long term, various numbers in the program seem very laborious.

How do you deal with such problems in the program?

Now we are thinking:

  1. Restrict programmers to use numbers to add tags without authorization, and add a class such:

class action{    const EDIT = 0;    const VIEW = 1;    //...}

All must be used by the parameter action class.

2. use the open-source enumeration class on github for implementation.
Such as: https://github.com/myclabs/ph...

Enumeration classes are a good choice, especially when the entire project tends to be object-oriented.

The two methods you listed are similar, except that the enumeration class provides more functions.
Select based on your actual needs.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.