Can you use static constants in PHP?

后端 未结 6 1044
面向向阳花
面向向阳花 2021-02-01 12:55

I expected the following to work but it doesn\'t seem to.



        
6条回答
  •  隐瞒了意图╮
    2021-02-01 13:17

    You can use const in class like this:

    class Patterns {
        const EMAIL = "/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix";
        const INT = "/^\d+$/";
        const USERNAME = "/^\w+$/";
    }
    

    And can access USERNAME const like this:

    Patterns::USERNAME
    

提交回复
热议问题