Is it safe to have 1 letter class names in PHP, e.g A, B, C

前端 未结 7 1966
野的像风
野的像风 2021-02-07 19:13

Is it safe to have single letter class names like A, B, P, etc?

相关标签:
7条回答
  • 2021-02-07 19:20

    only safe if it's a class that communicates with no other by the same name

    0 讨论(0)
  • 2021-02-07 19:22

    Why should it be unsafe? You may use them, if you want. It only is discouraged, because single char class names aren't very descriptive...

    Maybe you want to give the class a normal name but let the user import it with a short alias?

    use Some\Long\But\Descriptive\Classname as A;
    
    0 讨论(0)
  • 2021-02-07 19:23

    Safe, yes. Readable, no.

    0 讨论(0)
  • 2021-02-07 19:25

    No.

    Your future self will build a time machine for the sole purpose of slapping you for writing such unreadable code. And then, a paradox will result, and all of reality as we know it will be destroyed.

    0 讨论(0)
  • 2021-02-07 19:31

    Yeah there is nothing stopping you except for the confusion factor.

    0 讨论(0)
  • 2021-02-07 19:33

    There's no reason why it shouldn't be, but it's more useful to give your classes a meaningful name

    EDIT

    Link to PHP naming guide

    0 讨论(0)
提交回复
热议问题